Debian Codegraph @

gcc/testsuite/c-c++-common/cpp/pragma-push-pop-utf8.c

raw
1 /* { dg-do preprocess } */
2 /* { dg-options "-std=c11 -pedantic" { target c } } */
3 /* { dg-options "-std=c++11 -pedantic" { target c++ } } */
4 /* { dg-additional-options "-Wall" } */
5
6 /* PR preprocessor/109704 */
7
8 /* Verify basic operations for different extended identifiers... */
9
10 /* ...dollar sign. */
11 #define $x 1
12 #pragma push_macro("$x")
13 #undef $x
14 #define $x 0
15 #pragma pop_macro("$x")
16 #if !$x
17 #error $x
18 #endif
19 #define $x 1
20 _Pragma("push_macro(\"$x\")")
21 #undef $x
22 #define $x 0
23 _Pragma("pop_macro(\"$x\")")
24 #if !$x
25 #error $x
26 #endif
27 #define x$ 1
28 #pragma push_macro("x$")
29 #undef x$
30 #define x$ 0
31 #pragma pop_macro("x$")
32 #if !x$
33 #error x$
34 #endif
35 #define x$ 1
36 _Pragma("push_macro(\"x$\")")
37 #undef x$
38 #define x$ 0
39 _Pragma("pop_macro(\"x$\")")
40 #if !x$
41 #error x$
42 #endif
43
44 /* ...UCN. */
45 #define \u03B1x 1
46 #pragma push_macro("\u03B1x")
47 #undef \u03B1x
48 #define \u03B1x 0
49 #pragma pop_macro("\u03B1x")
50 #if !\u03B1x
51 #error \u03B1x
52 #endif
53 #define \u03B1x 1
54 _Pragma("push_macro(\"\\u03B1x\")")
55 #undef \u03B1x
56 #define \u03B1x 0
57 _Pragma("pop_macro(\"\\u03B1x\")")
58 #if !\u03B1x
59 #error \u03B1x
60 #endif
61 #define x\u03B1 1
62 #pragma push_macro("x\u03B1")
63 #undef x\u03B1
64 #define x\u03B1 0
65 #pragma pop_macro("x\u03B1")
66 #if !x\u03B1
67 #error x\u03B1
68 #endif
69 #define x\u03B1 1
70 _Pragma("push_macro(\"x\\u03B1\")")
71 #undef x\u03B1
72 #define x\u03B1 0
73 _Pragma("pop_macro(\"x\\u03B1\")")
74 #if !x\u03B1
75 #error x\u03B1
76 #endif
77
78 /* ...UTF-8. */
79 #define πx 1
80 #pragma push_macro("πx")
81 #undef πx
82 #define πx 0
83 #pragma pop_macro("πx")
84 #if !πx
85 #error πx
86 #endif
87 #define πx 1
88 _Pragma("push_macro(\"πx\")")
89 #undef πx
90 #define πx 0
91 _Pragma("pop_macro(\"πx\")")
92 #if !πx
93 #error πx
94 #endif
95 #define xπ 1
96 #pragma push_macro("xπ")
97 #undef xπ
98 #define xπ 0
99 #pragma pop_macro("xπ")
100 #if !xπ
101 #error xπ
102 #endif
103 #define xπ 1
104 _Pragma("push_macro(\"xπ\")")
105 #undef xπ
106 #define xπ 0
107 _Pragma("pop_macro(\"xπ\")")
108 #if !xπ
109 #error xπ
110 #endif
111
112 /* Verify UCN and UTF-8 can be intermixed. */
113 #define ħ_0 1
114 #pragma push_macro("ħ_0")
115 #undef ħ_0
116 #define ħ_0 0
117 #if ħ_0
118 #error ħ_0 ħ_0 \U00000127_0
119 #endif
120 #pragma pop_macro("\U00000127_0")
121 #if !ħ_0
122 #error ħ_0 ħ_0 \U00000127_0
123 #endif
124 #define ħ_1 1
125 #pragma push_macro("\U00000127_1")
126 #undef ħ_1
127 #define ħ_1 0
128 #if ħ_1
129 #error ħ_1 \U00000127_1 ħ_1
130 #endif
131 #pragma pop_macro("ħ_1")
132 #if !ħ_1
133 #error ħ_1 \U00000127_1 ħ_1
134 #endif
135 #define ħ_2 1
136 #pragma push_macro("\U00000127_2")
137 #undef ħ_2
138 #define ħ_2 0
139 #if ħ_2
140 #error ħ_2 \U00000127_2 \U00000127_2
141 #endif
142 #pragma pop_macro("\U00000127_2")
143 #if !ħ_2
144 #error ħ_2 \U00000127_2 \U00000127_2
145 #endif
146 #define \U00000127_3 1
147 #pragma push_macro("ħ_3")
148 #undef \U00000127_3
149 #define \U00000127_3 0
150 #if \U00000127_3
151 #error \U00000127_3 ħ_3 ħ_3
152 #endif
153 #pragma pop_macro("ħ_3")
154 #if !\U00000127_3
155 #error \U00000127_3 ħ_3 ħ_3
156 #endif
157 #define \U00000127_4 1
158 #pragma push_macro("ħ_4")
159 #undef \U00000127_4
160 #define \U00000127_4 0
161 #if \U00000127_4
162 #error \U00000127_4 ħ_4 \U00000127_4
163 #endif
164 #pragma pop_macro("\U00000127_4")
165 #if !\U00000127_4
166 #error \U00000127_4 ħ_4 \U00000127_4
167 #endif
168 #define \U00000127_5 1
169 #pragma push_macro("\U00000127_5")
170 #undef \U00000127_5
171 #define \U00000127_5 0
172 #if \U00000127_5
173 #error \U00000127_5 \U00000127_5 ħ_5
174 #endif
175 #pragma pop_macro("ħ_5")
176 #if !\U00000127_5
177 #error \U00000127_5 \U00000127_5 ħ_5
178 #endif
179
180 /* Verify invalid input produces no diagnostics. */
181 #pragma push_macro("") /* { dg-bogus "." } */
182 #pragma push_macro("\u") /* { dg-bogus "." } */
183 #pragma push_macro("\u0000") /* { dg-bogus "." } */
184 #pragma push_macro("not a single identifier") /* { dg-bogus "." } */
185 #pragma push_macro("invalid╬character") /* { dg-bogus "." } */
186 #pragma push_macro("\u0300invalid_start") /* { dg-bogus "." } */
187 #pragma push_macro("#include <cstdlib>") /* { dg-bogus "." } */
188
189 /* Verify end-of-line diagnostics for valid and invalid input. */
190 #pragma push_macro("ö") oops /* { dg-warning "extra tokens" } */
191 #pragma push_macro("") oops /* { dg-warning "extra tokens" } */
192 #pragma push_macro("\u") oops /* { dg-warning "extra tokens" } */
193 #pragma push_macro("\u0000") oops /* { dg-warning "extra tokens" } */
194 #pragma push_macro("not a single identifier") oops /* { dg-warning "extra tokens" } */
195 #pragma push_macro("invalid╬character") oops /* { dg-warning "extra tokens" } */
196 #pragma push_macro("\u0300invalid_start") oops /* { dg-warning "extra tokens" } */
197 #pragma push_macro("#include <cstdlib>") oops /* { dg-warning "extra tokens" } */
198
199 /* Verify expected diagnostics. */
200 #pragma push_macro() /* { dg-error {invalid '#pragma push_macro'} } */
201 #pragma pop_macro() /* { dg-error {invalid '#pragma pop_macro'} } */
202 _Pragma("push_macro(0)") /* { dg-error {invalid '#pragma push_macro'} } */
203 _Pragma("pop_macro(\"oops\"") /* { dg-error {invalid '#pragma pop_macro'} } */