1 // RUN: %clang_cc1 %s -fsyntax-only -std=c99 -pedantic -verify=expected,ext -Wundef -DTRIGRAPHS=1
2 // RUN: %clang_cc1 %s -fsyntax-only -std=c2x -pedantic -verify=expected,ext -Wundef -DTRIGRAPHS=1
3 // RUN: %clang_cc1 %s -fsyntax-only -x c++ -pedantic -verify=expected,ext -Wundef -fno-trigraphs
4 // RUN: %clang_cc1 %s -fsyntax-only -x c++ -std=c++23 -pedantic -ftrigraphs -DTRIGRAPHS=1 -verify=expected,cxx23 -Wundef -Wpre-c++23-compat
5 // RUN: %clang_cc1 %s -fsyntax-only -x c++ -pedantic -verify=expected,ext -Wundef -ftrigraphs -DTRIGRAPHS=1
6 // RUN: not %clang_cc1 %s -fsyntax-only -std=c99 -pedantic -Wundef 2>&1 | FileCheck -strict-whitespace %s
11 #error "This should never happen"
15 #error "This should never happen"
19 #error "This should never happen"
22 #if a\u{FD}() // ext-warning {{extension}} cxx23-warning {{before C++23}}
23 #error "This should never happen"
26 #if \uarecool // expected-warning{{incomplete universal character name; treating as '\' followed by identifier}} expected-error {{invalid token at start of a preprocessor expression}}
28 #if \uwerecool // expected-warning{{\u used with no following hex digits; treating as '\' followed by identifier}} expected-error {{invalid token at start of a preprocessor expression}}
30 #if \U0001000 // expected-warning{{incomplete universal character name; treating as '\' followed by identifier}} expected-error {{invalid token at start of a preprocessor expression}}
33 // Make sure we reject disallowed UCNs
34 #define \ufffe // expected-error {{macro name must be an identifier}}
35 #define \U10000000 // expected-error {{macro name must be an identifier}}
36 #define \u0061 // expected-error {{character 'a' cannot be specified by a universal character name}} expected-error {{macro name must be an identifier}}
37 #define \u{fffe} // expected-error {{macro name must be an identifier}} \
38 // ext-warning {{extension}} cxx23-warning {{before C++23}}
39 #define \N{ALERT} // expected-error {{universal character name refers to a control character}} \
40 // expected-error {{macro name must be an identifier}} \
41 // ext-warning {{extension}} cxx23-warning {{before C++23}}
42 #define \N{WASTEBASKET} // expected-error {{macro name must be an identifier}} \
43 // ext-warning {{extension}} cxx23-warning {{before C++23}}
44 #define a\u0024a // expected-error {{character '$' cannot be specified by a universal character name}} \
45 // expected-warning {{requires whitespace after the macro name}}
47 #if \u0110 // expected-warning {{is not defined, evaluates to 0}}
52 #if \u0110 // expected-error {{division by zero in preprocessor expression}}
55 #define STRINGIZE(X) # X
57 extern int check_size
[sizeof(STRINGIZE(\u0112)) == 3 ? 1 : -1];
59 // Check that we still diagnose disallowed UCNs in #if 0 blocks.
60 // C99 5.1.1.2p1 and C++11 [lex.phases]p1 dictate that preprocessor tokens are
61 // formed before directives are parsed.
62 // expected-error@+4 {{character 'a' cannot be specified by a universal character name}}
64 #define \ufffe // okay
65 #define \U10000000 // okay
66 #define \u0061 // error, but -verify only looks at comments outside #if 0
70 // A UCN formed by token pasting is undefined in both C99 and C++.
71 // Right now we don't do anything special, which causes us to coincidentally
72 // accept the first case below but reject the second two.
73 #define PASTE(A, B) A ## B
74 extern int PASTE(\
, u00FD
);
75 extern int PASTE(\u
, 00FD
); // expected-warning{{\u used with no following hex digits}}
76 extern int PASTE(\u0
, 0FD
); // expected-warning{{incomplete universal character name}}
78 // expected-error@-3 {{expected unqualified-id}}
79 // expected-error@-3 {{expected unqualified-id}}
81 // expected-error@-6 {{expected identifier}}
82 // expected-error@-6 {{expected identifier}}
86 // A UCN produced by line splicing is valid in C99 but undefined in C++.
87 // Since undefined behavior can do anything including working as intended,
88 // we just accept it in C++ as well.;
89 #define newline_1_\u00F\
91 #define newline_2_\u00\
107 #if (newline_1_\u00FC && newline_2_\u00FC && newline_3_\u00FC && \
108 newline_4_\u00FC && newline_5_\u00FC)
110 #error "Line splicing failed to produce UCNs"
114 #define capital_u_\U00FC
115 // expected-warning@-1 {{incomplete universal character name}} expected-note@-1 {{did you mean to use '\u'?}} expected-warning@-1 {{whitespace}}
116 // CHECK: note: did you mean to use '\u'?
117 // CHECK-NEXT: {{^ .* | #define capital_u_\U00FC}}
118 // CHECK-NEXT: {{^ | \^}}
119 // CHECK-NEXT: {{^ | u}}
121 #define \u{} // expected-warning {{empty delimited universal character name; treating as '\' 'u' '{' '}'}} expected-error {{macro name must be an identifier}}
122 #define \u1{123} // expected-warning {{incomplete universal character name; treating as '\' followed by identifier}} expected-error {{macro name must be an identifier}}
123 #define \u{123456789} // expected-error {{hex escape sequence out of range}} expected-error {{macro name must be an identifier}}
124 #define \u{ // expected-warning {{incomplete delimited universal character name; treating as '\' 'u' '{' identifier}} expected-error {{macro name must be an identifier}}
125 #define \u{fgh} // expected-warning {{incomplete delimited universal character name; treating as '\' 'u' '{' identifier}} expected-error {{macro name must be an identifier}}
127 // expected-warning@-1 {{incomplete delimited universal character name; treating as '\' 'N' '{' identifier}}
128 // expected-error@-2 {{macro name must be an identifier}}
129 #define \N{} // expected-warning {{empty delimited universal character name; treating as '\' 'N' '{' '}'}} expected-error {{macro name must be an identifier}}
130 #define \N{NOTATHING} // expected-error {{'NOTATHING' is not a valid Unicode character name}} \
131 // expected-error {{macro name must be an identifier}}
132 #define \NN // expected-warning {{incomplete universal character name; treating as '\' followed by identifier}} expected-error {{macro name must be an identifier}}
133 #define \N{GREEK_SMALL-LETTERALPHA} // expected-error {{'GREEK_SMALL-LETTERALPHA' is not a valid Unicode character name}} \
134 // expected-note {{characters names in Unicode escape sequences are sensitive to case and whitespaces}}
135 #define \N{🤡} // expected-error {{'🤡' is not a valid Unicode character name}} \
136 // expected-error {{macro name must be an identifier}}
138 #define CONCAT(A, B) A##B
140 , CAPITALLETTERALPHA
});
141 // expected-error@-2 {{expected}} \
142 // expected-warning@-2 {{incomplete delimited universal character name}}
145 LATIN CAPITAL LETTER A WITH GRAVE
};
146 //ext-warning@-2 {{extension}} cxx23-warning@-2 {{before C++23}}
149 int \N
??<GREEK CAPITAL LETTER ALPHA
??> = 0; // cxx23-warning {{before C++23}} \
150 //ext-warning {{extension}}\
151 // expected-warning 2{{trigraph converted}}
153 int a\N
{LATIN CAPITAL LETTER A WITH GRAVE
??>; // expected-warning {{trigraph converted}}
157 int a\N
{LATIN CAPITAL LETTER A WITH GRAVE
??>;
158 // expected-warning@-1 {{trigraph ignored}}\
159 // expected-warning@-1 {{incomplete}}\
160 // expected-error@-1 {{expected unqualified-id}}
164 int A\N
{LEFT
-TO
-RIGHT OVERRIDE
}; // expected-error {{character <U+202D> not allowed in an identifier}}