]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Guard uses of char8_t with __cpp_char8_t [PR114519]
authorJonathan Wakely <jwakely@redhat.com>
Thu, 28 Mar 2024 21:29:17 +0000 (21:29 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 2 Apr 2024 19:55:32 +0000 (20:55 +0100)
libstdc++-v3/ChangeLog:

PR libstdc++/114519
* include/bits/unicode.h (_Utf8_view): Guard with check for
char8_t being enabled.
(__literal_encoding_is_unicode): Guard use of char8_t with check
for it being enabled.
* testsuite/std/format/functions/114519.cc: New test.

libstdc++-v3/include/bits/unicode.h
libstdc++-v3/testsuite/std/format/functions/114519.cc [new file with mode: 0644]

index 51bf02e927fc9c8b67e344b33da333f877009984..0e95c86a0b00ec0cd883d2c017719ff26809db61 100644 (file)
@@ -578,8 +578,10 @@ namespace __unicode
       constexpr bool empty() const { return ranges::empty(_M_base); }
     };
 
+#ifdef __cpp_char8_t
   template<typename _View>
     using _Utf8_view = _Utf_view<char8_t, _View>;
+#endif
   template<typename _View>
     using _Utf16_view = _Utf_view<char16_t, _View>;
   template<typename _View>
@@ -991,12 +993,14 @@ inline namespace __v15_1_0
     consteval bool
     __literal_encoding_is_unicode()
     {
-      if constexpr (is_same_v<_CharT, char8_t>)
-       return true;
-      else if constexpr (is_same_v<_CharT, char16_t>)
+      if constexpr (is_same_v<_CharT, char16_t>)
        return true;
       else if constexpr (is_same_v<_CharT, char32_t>)
          return true;
+#ifdef __cpp_char8_t
+      else if constexpr (is_same_v<_CharT, char8_t>)
+       return true;
+#endif
 
       const char* __enc = "";
 
diff --git a/libstdc++-v3/testsuite/std/format/functions/114519.cc b/libstdc++-v3/testsuite/std/format/functions/114519.cc
new file mode 100644 (file)
index 0000000..25a112a
--- /dev/null
@@ -0,0 +1,3 @@
+// { dg-do compile { target c++20 } }
+// { dg-options "-fno-char8_t" }
+#include <format>