From bf46c8a21ffa288d756cea2ad455b5f012c3231f Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Fri, 6 Sep 2024 04:07:56 -0700 Subject: [PATCH] fix Range under libc++ >= 19 where basic_string_view only allows char types Summary: LLVM 19 removed the base templates for `std::char_traits` and only allows the following types to be used `char`, `wchar_t`, `char8_t`, `char16_t`, `char32_t`. From the [release notes](https://github.com/llvm/llvm-project/blob/release/19.x/libcxx/docs/ReleaseNotes/19.rst): > The base template for `std::char_traits` has been removed in LLVM 19. If you are using `std::char_traits` with types other than `char`, `wchar_t`, `char8_t`, `char16_t`, `char32_t` or a custom character type for which you specialized `std::char_traits`, your code will stop working. The Standard does not mandate that a base template is provided, and such a base template is bound to be incorrect for some types, which could currently cause unexpected behavior while going undetected. Fixes the following eror: ``` llvm-project/libcxx/include/string_view:300:42: error: implicit instantiation of undefined template 'std::char_traits' 300 | static_assert(is_same<_CharT, typename traits_type::char_type>::value, | ^ llvm-project/libcxx/include/__type_traits/is_constructible.h:24:79: note: in instantiation of template class 'std::basic_string_view' requested here 24 | struct _LIBCPP_TEMPLATE_VIS is_constructible : public integral_constant {}; | ^ folly/Traits.h:694:24: note: in instantiation of template class 'std::is_constructible, const unsigned char *const &, unsigned long>' requested here 694 | : std::conditional, T>::type {}; | ^ folly/Range.h:647:9: note: in instantiation of template class 'folly::Conjunction, const unsigned char *const &, unsigned long>, std::is_constructible, std::basic_string_view>>' requested here 647 | : Conjunction< | ^ folly/Range.h:666:16: note: in instantiation of template class 'folly::Range::IsConstructibleViaStringView>' requested here 666 | !IsConstructibleViaStringView::value, | ^ folly/Range.h:668:22: note: while substituting prior template arguments into non-type template parameter [with Tgt = folly::Range] 668 | constexpr explicit operator Tgt() const noexcept( | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 669 | std::is_nothrow_constructible::value) { | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 670 | return Tgt(b_, walk_size()); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 671 | } | ~ folly/Range.h:1665:19: note: while substituting deduced template arguments into function template 'operator type-parameter-0-0' [with Tgt = folly::Range, $1 = (no value)] 1665 | StringPiece(haystack), StringPiece(needles)); | ^ llvm-project/libcxx/include/__string/char_traits.h:45:8: note: template is declared here 45 | struct char_traits; | ^ ``` Reviewed By: thevinster Differential Revision: D62275652 fbshipit-source-id: fc4288c7113f7a76b96f21d4d3766d75bec11988 --- folly/Range.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/folly/Range.h b/folly/Range.h index 42cd92d69fb..d87914a99c7 100644 --- a/folly/Range.h +++ b/folly/Range.h @@ -638,7 +638,7 @@ class Range { template struct StringViewType // : std::conditional< - std::is_trivial::value, + detail::range_is_char_type_v_, std::basic_string_view, NotStringView> {};