if (flag_threadsafe_statics)
cpp_define (pfile, "__cpp_threadsafe_static_init=200806L");
if (flag_char8_t)
- cpp_define (pfile, "__cpp_char8_t=201811L");
+ cpp_define (pfile, "__cpp_char8_t=202207L");
#ifndef THREAD_MODEL_SPEC
/* Targets that define THREAD_MODEL_SPEC need to define
__STDCPP_THREADS__ in their config/XXX/XXX-c.c themselves. */
if (ordinary_char_type_p (to_char_type)
&& ordinary_char_type_p (from_char_type))
return true;
+
+ /* P2513 (C++20/C++23): "an array of char or unsigned char may
+ be initialized by a UTF-8 string literal, or by such a string
+ literal enclosed in braces." */
+ if (from_char_type == char8_type_node
+ && (to_char_type == char_type_node
+ || to_char_type == unsigned_char_type_node))
+ return true;
+
return false;
}
#ifndef __cpp_char8_t
# error "__cpp_char8_t"
-#elif __cpp_char8_t != 201811
-# error "__cpp_char8_t != 201811"
+#elif __cpp_char8_t != 202207
+# error "__cpp_char8_t != 202207"
#endif
#ifndef __cpp_designated_initializers
--- /dev/null
+// PR c++/106656 - P2513 - char8_t Compatibility and Portability Fixes
+// { dg-do compile { target c++20 } }
+
+const char *p1 = u8""; // { dg-error "invalid conversion" }
+const unsigned char *p2 = u8""; // { dg-error "invalid conversion" }
+const signed char *p3 = u8""; // { dg-error "invalid conversion" }
+const char *p4 = { u8"" }; // { dg-error "invalid conversion" }
+const unsigned char *p5 = { u8"" }; // { dg-error "invalid conversion" }
+const signed char *p6 = { u8"" }; // { dg-error "invalid conversion" }
+const char *p7 = static_cast<const char *>(u8""); // { dg-error "invalid" }
+const char a1[] = u8"text";
+const unsigned char a2[] = u8"";
+const signed char a3[] = u8""; // { dg-error "cannot initialize array" }
+const char a4[] = { u8"text" };
+const unsigned char a5[] = { u8"" };
+const signed char a6[] = { u8"" }; // { dg-error "cannot initialize array" }
+
+const char *
+resource_id ()
+{
+ static const char res_id[] = u8"";
+ return res_id;
+}
+
+const char8_t x[] = "fail"; // { dg-error "cannot initialize array" }
+
+void fn (const char a[]);
+void
+g ()
+{
+ fn (u8"z"); // { dg-error "invalid conversion" }
+}
+
+char c = u8'c';
+unsigned char uc = u8'c';
+signed char sc = u8'c';
+char8_t c8 = 'c';
--- /dev/null
+// PR c++/106656 - P2513 - char8_t Compatibility and Portability Fixes
+// { dg-do compile { target c++20 } }
+// [diff.cpp20.dcl]
+
+struct A {
+ char8_t s[10];
+};
+struct B {
+ char s[10];
+};
+
+void f(A);
+void f(B);
+
+int main() {
+ f({u8""}); // { dg-error "ambiguous" }
+}
#ifndef __cpp_char8_t
# error "__cpp_char8_t"
-#elif __cpp_char8_t != 201811
-# error "__cpp_char8_t != 201811"
+#elif __cpp_char8_t != 202207
+# error "__cpp_char8_t != 202207"
#endif
#ifndef __cpp_designated_initializers
#if !defined(__cpp_char8_t)
# error __cpp_char8_t is not defined!
-#elif __cpp_char8_t != 201811
-# error __cpp_char8_t != 201811
+#elif __cpp_char8_t != 202207
+# error __cpp_char8_t != 202207
#endif
const char8_t (&rca5)[2] = u"x"; // { dg-error "invalid initialization of reference of type .const char8_t ....... from expression of type .const char16_t ...." "char8_t" }
char ca1[] = "x";
-char ca2[] = u8"x"; // { dg-error "from a string literal with type array of .char8_t." "char8_t" }
+char ca2[] = u8"x";
char8_t ca3[] = "x"; // { dg-error "from a string literal with type array of .char." "char8_t" }
char8_t ca4[] = u8"x";
char8_t ca5[] = u"x"; // { dg-error "from a string literal with type array of .char16_t." "char8_t" }
signed char sca2[] = u8"x"; // { dg-error "from a string literal with type array of .char8_t." "char8_t" }
unsigned char uca1[] = "x";
-unsigned char uca2[] = u8"x"; // { dg-error "from a string literal with type array of .char8_t." "char8_t" }
+unsigned char uca2[] = u8"x";