1 // RUN: %clang_cc1 %s -fsyntax-only -std=c99 -pedantic -verify=expected,ext -Wundef
2 // RUN: %clang_cc1 %s -fsyntax-only -x c++ -pedantic -verify=expected,ext -Wundef
3 // RUN: %clang_cc1 %s -fsyntax-only -x c++ -std=c++2b -pedantic -ftrigraphs -verify=expected,cxx2b -Wundef -Wpre-c++2b-compat
4 // RUN: %clang_cc1 %s -fsyntax-only -x c++ -pedantic -verify=expected,ext -Wundef -ftrigraphs -DTRIGRAPHS=1
5 // RUN: not %clang_cc1 %s -fsyntax-only -std=c99 -pedantic -Wundef 2>&1 | FileCheck -strict-whitespace %s
6 
7 #define \u00FC
8 #define a\u00FD() 0
9 #ifndef \u00FC
10 #error "This should never happen"
11 #endif
12 
13 #if a\u00FD()
14 #error "This should never happen"
15 #endif
16 
17 #if a\U000000FD()
18 #error "This should never happen"
19 #endif
20 
21 #if a\u{FD}() // ext-warning {{extension}} cxx2b-warning {{before C++2b}}
22 #error "This should never happen"
23 #endif
24 
25 #if \uarecool // expected-warning{{incomplete universal character name; treating as '\' followed by identifier}} expected-error {{invalid token at start of a preprocessor expression}}
26 #endif
27 #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}}
28 #endif
29 #if \U0001000  // expected-warning{{incomplete universal character name; treating as '\' followed by identifier}} expected-error {{invalid token at start of a preprocessor expression}}
30 #endif
31 
32 // Make sure we reject disallowed UCNs
33 #define \ufffe // expected-error {{macro name must be an identifier}}
34 #define \U10000000      // expected-error {{macro name must be an identifier}}
35 #define \u0061          // expected-error {{character 'a' cannot be specified by a universal character name}} expected-error {{macro name must be an identifier}}
36 #define \u{fffe}        // expected-error {{macro name must be an identifier}} \
37                         // ext-warning {{extension}} cxx2b-warning {{before C++2b}}
38 #define \N{ALERT}       // expected-error {{universal character name refers to a control character}} \
39                    // expected-error {{macro name must be an identifier}} \
40                    // ext-warning {{extension}} cxx2b-warning {{before C++2b}}
41 #define \N{WASTEBASKET} // expected-error {{macro name must be an identifier}} \
42                         // ext-warning {{extension}} cxx2b-warning {{before C++2b}}
43 
44 #define a\u0024
45 
46 #if \u0110 // expected-warning {{is not defined, evaluates to 0}}
47 #endif
48 
49 
50 #define \u0110 1 / 0
51 #if \u0110 // expected-error {{division by zero in preprocessor expression}}
52 #endif
53 
54 #define STRINGIZE(X) # X
55 
56 extern int check_size[sizeof(STRINGIZE(\u0112)) == 3 ? 1 : -1];
57 
58 // Check that we still diagnose disallowed UCNs in #if 0 blocks.
59 // C99 5.1.1.2p1 and C++11 [lex.phases]p1 dictate that preprocessor tokens are
60 // formed before directives are parsed.
61 // expected-error@+4 {{character 'a' cannot be specified by a universal character name}}
62 #if 0
63 #define \ufffe // okay
64 #define \U10000000 // okay
65 #define \u0061 // error, but -verify only looks at comments outside #if 0
66 #endif
67 
68 
69 // A UCN formed by token pasting is undefined in both C99 and C++.
70 // Right now we don't do anything special, which causes us to coincidentally
71 // accept the first case below but reject the second two.
72 #define PASTE(A, B) A ## B
73 extern int PASTE(\, u00FD);
74 extern int PASTE(\u, 00FD); // expected-warning{{\u used with no following hex digits}}
75 extern int PASTE(\u0, 0FD); // expected-warning{{incomplete universal character name}}
76 #ifdef __cplusplus
77 // expected-error@-3 {{expected unqualified-id}}
78 // expected-error@-3 {{expected unqualified-id}}
79 #else
80 // expected-error@-6 {{expected identifier}}
81 // expected-error@-6 {{expected identifier}}
82 #endif
83 
84 
85 // A UCN produced by line splicing is valid in C99 but undefined in C++.
86 // Since undefined behavior can do anything including working as intended,
87 // we just accept it in C++ as well.;
88 #define newline_1_\u00F\
89 C 1
90 #define newline_2_\u00\
91 F\
92 C 1
93 #define newline_3_\u\
94 00\
95 FC 1
96 #define newline_4_\\
97 u00FC 1
98 #define newline_5_\\
99 u\
100 \
101 0\
102 0\
103 F\
104 C 1
105 
106 #if (newline_1_\u00FC && newline_2_\u00FC && newline_3_\u00FC && \
107      newline_4_\u00FC && newline_5_\u00FC)
108 #else
109 #error "Line splicing failed to produce UCNs"
110 #endif
111 
112 
113 #define capital_u_\U00FC
114 // expected-warning@-1 {{incomplete universal character name}} expected-note@-1 {{did you mean to use '\u'?}} expected-warning@-1 {{whitespace}}
115 // CHECK: note: did you mean to use '\u'?
116 // CHECK-NEXT:   #define capital_u_\U00FC
117 // CHECK-NEXT: {{^                   \^}}
118 // CHECK-NEXT: {{^                   u}}
119 
120 #define \u{}           // expected-warning {{empty delimited universal character name; treating as '\' 'u' '{' '}'}} expected-error {{macro name must be an identifier}}
121 #define \u{123456789}  // expected-error {{hex escape sequence out of range}} expected-error {{macro name must be an identifier}}
122 #define \u{            // expected-warning {{incomplete delimited universal character name; treating as '\' 'u' '{' identifier}} expected-error {{macro name must be an identifier}}
123 #define \u{fgh}        // expected-warning {{incomplete delimited universal character name; treating as '\' 'u' '{' identifier}} expected-error {{macro name must be an identifier}}
124 #define \N{            // expected-warning {{incomplete delimited universal character name; treating as '\' 'N' '{' identifier}} expected-error {{macro name must be an identifier}}
125 #define \N{}           // expected-warning {{empty delimited universal character name; treating as '\' 'N' '{' '}'}} expected-error {{macro name must be an identifier}}
126 #define \N{NOTATHING}  // expected-error {{'NOTATHING' is not a valid Unicode character name}} \
127                        // expected-error {{macro name must be an identifier}}
128 #define \NN            // expected-warning {{incomplete universal character name; treating as '\' followed by identifier}} expected-error {{macro name must be an identifier}}
129 #define \N{GREEK_SMALL-LETTERALPHA}  // expected-error {{'GREEK_SMALL-LETTERALPHA' is not a valid Unicode character name}} \
130                                      // expected-note {{characters names in Unicode escape sequences are sensitive to case and whitespaces}}
131 
132 #define CONCAT(A, B) A##B
133 int CONCAT(\N{GREEK, CAPITALLETTERALPHA}); // expected-error{{expected}} \
134                                            // expected-warning {{incomplete delimited universal character name}}
135 
136 #ifdef TRIGRAPHS
137 int \N??<GREEK CAPITAL LETTER ALPHA??> = 0; // expected-warning{{extension}} cxx2b-warning {{before C++2b}} \
138                                             // expected-warning 2{{trigraph converted}}
139 
140 #endif
141