1 /* Test Unicode strings in C11. Test valid code. */
3 /* { dg-options "-std=c11 -pedantic-errors" } */
5 /* More thorough tests are in c-c++-common/raw-string-*.c; this test
6 verifies the particular subset (Unicode but not raw strings) that
9 typedef __CHAR16_TYPE__ char16_t
;
10 typedef __CHAR32_TYPE__ char32_t
;
11 typedef __SIZE_TYPE__
size_t;
13 extern void abort (void);
14 extern void exit (int);
15 extern int memcmp (const void *, const void *, size_t);
26 const char su8
[] = u8
"a\u010d";
27 const char su8a
[] = "a\xc4\x8d";
29 const char16_t su16
[] = u
"\u0567";
30 const char16_t su16a
[] = { 0x0567, 0 };
32 const char32_t su32
[] = U
"\u0123";
33 const char32_t su32a
[] = { 0x0123, 0 };
35 const char tu
[] = R
"a";
36 const char tua
[] = "(R)a";
38 const char tu8
[] = u8R
"b";
39 const char tu8a
[] = "(u8R)b";
41 const char tu16
[] = uR
"c";
42 const char tu16a
[] = "(uR)c";
44 const char tu32
[] = UR
"d";
45 const char tu32a
[] = "(UR)d";
47 const char tl
[] = LR
"e";
48 const char tla
[] = "(LR)e";
51 const char ts
[] = str(u
"a" U
"b" u8
"c");
52 const char tsa
[] = "u\"a\" U\"b\" u8\"c\"";
54 /* GCC always uses UTF-16 and UTF-32 for char16_t and char32_t. */
55 #ifndef __STDC_UTF_16__
56 #error "__STDC_UTF_16__ not defined"
58 #ifndef __STDC_UTF_32__
59 #error "__STDC_UTF_32__ not defined"
61 #define xstr(x) str(x)
62 const char tm16
[] = xstr(__STDC_UTF_16__
);
63 const char tm16a
[] = "1";
64 const char tm32
[] = xstr(__STDC_UTF_32__
);
65 const char tm32a
[] = "1";
70 if (sizeof (su8
) != sizeof (su8a
)
71 || memcmp (su8
, su8a
, sizeof (su8
)) != 0)
73 if (sizeof (su16
) != sizeof (su16a
)
74 || memcmp (su16
, su16a
, sizeof (su16
)) != 0)
76 if (sizeof (su32
) != sizeof (su32a
)
77 || memcmp (su32
, su32a
, sizeof (su32
)) != 0)
79 if (sizeof (tu
) != sizeof (tua
)
80 || memcmp (tu
, tua
, sizeof (tu
)) != 0)
82 if (sizeof (tu8
) != sizeof (tu8a
)
83 || memcmp (tu8
, tu8a
, sizeof (tu8
)) != 0)
85 if (sizeof (tu16
) != sizeof (tu16a
)
86 || memcmp (tu16
, tu16a
, sizeof (tu16
)) != 0)
88 if (sizeof (tu32
) != sizeof (tu32a
)
89 || memcmp (tu32
, tu32a
, sizeof (tu32
)) != 0)
91 if (sizeof (tl
) != sizeof (tla
)
92 || memcmp (tl
, tla
, sizeof (tl
)) != 0)
94 if (sizeof (ts
) != sizeof (tsa
)
95 || memcmp (ts
, tsa
, sizeof (ts
)) != 0)
97 if (sizeof (tm16
) != sizeof (tm16a
)
98 || memcmp (tm16
, tm16a
, sizeof (tm16
)) != 0)
100 if (sizeof (tm32
) != sizeof (tm32a
)
101 || memcmp (tm32
, tm32a
, sizeof (tm32
)) != 0)
103 if (u
'\u0123' != 0x0123)
105 if (U
'\u0456' != 0x0456)