]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Use char for _Utf8_view if char8_t isn't available [PR114519]
authorJonathan Wakely <jwakely@redhat.com>
Tue, 2 Apr 2024 21:46:55 +0000 (22:46 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 8 Apr 2024 16:44:18 +0000 (17:44 +0100)
Instead of just omitting the definition of __unicode::_Utf8_view when
char8_t is disabled, we can make it use char instead.

libstdc++-v3/ChangeLog:

PR libstdc++/114519
* include/bits/unicode.h (_Utf8_view) [!__cpp_char8_t]: Define
using char instead of char8_t.
* testsuite/ext/unicode/view.cc: Use u8""sv literals to create
string views, instead of std::u8string_view.

libstdc++-v3/include/bits/unicode.h
libstdc++-v3/testsuite/ext/unicode/view.cc

index 0e95c86a0b00ec0cd883d2c017719ff26809db61..29813b743dc182851b8903fae9978cc31452725a 100644 (file)
@@ -581,6 +581,9 @@ namespace __unicode
 #ifdef __cpp_char8_t
   template<typename _View>
     using _Utf8_view = _Utf_view<char8_t, _View>;
+#else
+  template<typename _View>
+    using _Utf8_view = _Utf_view<char, _View>;
 #endif
   template<typename _View>
     using _Utf16_view = _Utf_view<char16_t, _View>;
index 79ea2bbc6b7e935ff731f0a2286a9b8d0342b207..ee23b0b1d8a3d818187e60192c89ea08ae37ab72 100644 (file)
@@ -10,7 +10,7 @@ using namespace std::string_view_literals;
 constexpr void
 test_utf8_to_utf8()
 {
-  const std::u8string_view s8 = u8"£🇬🇧 €🇪🇺 æбçδé ♠♥♦♣ 🤡";
+  const auto s8 = u8"£🇬🇧 €🇪🇺 æбçδé ♠♥♦♣ 🤡"sv;
   uc::_Utf8_view v(s8);
   VERIFY( std::ranges::distance(v) == s8.size() );
   VERIFY( std::ranges::equal(v,  s8) );
@@ -19,7 +19,7 @@ test_utf8_to_utf8()
 constexpr void
 test_utf8_to_utf16()
 {
-  const std::u8string_view s8  = u8"£🇬🇧 €🇪🇺 æбçδé ♠♥♦♣ 🤡";
+  const auto s8  = u8"£🇬🇧 €🇪🇺 æбçδé ♠♥♦♣ 🤡"sv;
   const std::u16string_view s16 = u"£🇬🇧 €🇪🇺 æбçδé ♠♥♦♣ 🤡";
   uc::_Utf16_view v(s8);
   VERIFY( std::ranges::distance(v) == s16.size() );