annotate clang/test/Preprocessor/ucn-pp-identifier.c @ 236:c4bab56944e8 llvm-original

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