Daily bump.
[official-gcc.git] / gcc / testsuite / gcc.dg / c11-uni-string-1.c
blob9f86bea826b75ca6dac55ddecea5b22aa231c58c
1 /* Test Unicode strings in C11. Test valid code. */
2 /* { dg-do run } */
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
7 is in C11. */
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);
17 #define R "(R)"
18 #define u8R "(u8R)"
19 #define uR "(uR)"
20 #define UR "(UR)"
21 #define LR "(LR)"
22 #define u8 randomu8
23 #define u randomu
24 #define U randomU
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";
50 #define str(x) #x
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"
57 #endif
58 #ifndef __STDC_UTF_32__
59 #error "__STDC_UTF_32__ not defined"
60 #endif
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";
67 int
68 main (void)
70 if (sizeof (su8) != sizeof (su8a)
71 || memcmp (su8, su8a, sizeof (su8)) != 0)
72 abort ();
73 if (sizeof (su16) != sizeof (su16a)
74 || memcmp (su16, su16a, sizeof (su16)) != 0)
75 abort ();
76 if (sizeof (su32) != sizeof (su32a)
77 || memcmp (su32, su32a, sizeof (su32)) != 0)
78 abort ();
79 if (sizeof (tu) != sizeof (tua)
80 || memcmp (tu, tua, sizeof (tu)) != 0)
81 abort ();
82 if (sizeof (tu8) != sizeof (tu8a)
83 || memcmp (tu8, tu8a, sizeof (tu8)) != 0)
84 abort ();
85 if (sizeof (tu16) != sizeof (tu16a)
86 || memcmp (tu16, tu16a, sizeof (tu16)) != 0)
87 abort ();
88 if (sizeof (tu32) != sizeof (tu32a)
89 || memcmp (tu32, tu32a, sizeof (tu32)) != 0)
90 abort ();
91 if (sizeof (tl) != sizeof (tla)
92 || memcmp (tl, tla, sizeof (tl)) != 0)
93 abort ();
94 if (sizeof (ts) != sizeof (tsa)
95 || memcmp (ts, tsa, sizeof (ts)) != 0)
96 abort ();
97 if (sizeof (tm16) != sizeof (tm16a)
98 || memcmp (tm16, tm16a, sizeof (tm16)) != 0)
99 abort ();
100 if (sizeof (tm32) != sizeof (tm32a)
101 || memcmp (tm32, tm32a, sizeof (tm32)) != 0)
102 abort ();
103 if (u'\u0123' != 0x0123)
104 abort ();
105 if (U'\u0456' != 0x0456)
106 abort ();
107 #undef u8
108 #define u8
109 if (u8'a' != 'a')
110 abort ();
111 exit (0);