annotate clang/test/Preprocessor/ucn-pp-identifier.c @ 150:1d019706d866

LLVM10
author anatofuz
date Thu, 13 Feb 2020 15:10:13 +0900
parents
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 %s -fsyntax-only -std=c99 -pedantic -verify -Wundef
anatofuz
parents:
diff changeset
2 // RUN: %clang_cc1 %s -fsyntax-only -x c++ -pedantic -verify -Wundef
anatofuz
parents:
diff changeset
3 // RUN: not %clang_cc1 %s -fsyntax-only -std=c99 -pedantic -Wundef 2>&1 | FileCheck -strict-whitespace %s
anatofuz
parents:
diff changeset
4
anatofuz
parents:
diff changeset
5 #define \u00FC
anatofuz
parents:
diff changeset
6 #define a\u00FD() 0
anatofuz
parents:
diff changeset
7 #ifndef \u00FC
anatofuz
parents:
diff changeset
8 #error "This should never happen"
anatofuz
parents:
diff changeset
9 #endif
anatofuz
parents:
diff changeset
10
anatofuz
parents:
diff changeset
11 #if a\u00FD()
anatofuz
parents:
diff changeset
12 #error "This should never happen"
anatofuz
parents:
diff changeset
13 #endif
anatofuz
parents:
diff changeset
14
anatofuz
parents:
diff changeset
15 #if a\U000000FD()
anatofuz
parents:
diff changeset
16 #error "This should never happen"
anatofuz
parents:
diff changeset
17 #endif
anatofuz
parents:
diff changeset
18
anatofuz
parents:
diff changeset
19 #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
20 #endif
anatofuz
parents:
diff changeset
21 #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
22 #endif
anatofuz
parents:
diff changeset
23 #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
24 #endif
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26 // Make sure we reject disallowed UCNs
anatofuz
parents:
diff changeset
27 #define \ufffe // expected-error {{macro name must be an identifier}}
anatofuz
parents:
diff changeset
28 #define \U10000000 // expected-error {{macro name must be an identifier}}
anatofuz
parents:
diff changeset
29 #define \u0061 // expected-error {{character 'a' cannot be specified by a universal character name}} expected-error {{macro name must be an identifier}}
anatofuz
parents:
diff changeset
30
anatofuz
parents:
diff changeset
31 #define a\u0024
anatofuz
parents:
diff changeset
32
anatofuz
parents:
diff changeset
33 #if \u0110 // expected-warning {{is not defined, evaluates to 0}}
anatofuz
parents:
diff changeset
34 #endif
anatofuz
parents:
diff changeset
35
anatofuz
parents:
diff changeset
36
anatofuz
parents:
diff changeset
37 #define \u0110 1 / 0
anatofuz
parents:
diff changeset
38 #if \u0110 // expected-error {{division by zero in preprocessor expression}}
anatofuz
parents:
diff changeset
39 #endif
anatofuz
parents:
diff changeset
40
anatofuz
parents:
diff changeset
41 #define STRINGIZE(X) # X
anatofuz
parents:
diff changeset
42
anatofuz
parents:
diff changeset
43 extern int check_size[sizeof(STRINGIZE(\u0112)) == 3 ? 1 : -1];
anatofuz
parents:
diff changeset
44
anatofuz
parents:
diff changeset
45 // Check that we still diagnose disallowed UCNs in #if 0 blocks.
anatofuz
parents:
diff changeset
46 // C99 5.1.1.2p1 and C++11 [lex.phases]p1 dictate that preprocessor tokens are
anatofuz
parents:
diff changeset
47 // formed before directives are parsed.
anatofuz
parents:
diff changeset
48 // expected-error@+4 {{character 'a' cannot be specified by a universal character name}}
anatofuz
parents:
diff changeset
49 #if 0
anatofuz
parents:
diff changeset
50 #define \ufffe // okay
anatofuz
parents:
diff changeset
51 #define \U10000000 // okay
anatofuz
parents:
diff changeset
52 #define \u0061 // error, but -verify only looks at comments outside #if 0
anatofuz
parents:
diff changeset
53 #endif
anatofuz
parents:
diff changeset
54
anatofuz
parents:
diff changeset
55
anatofuz
parents:
diff changeset
56 // A UCN formed by token pasting is undefined in both C99 and C++.
anatofuz
parents:
diff changeset
57 // Right now we don't do anything special, which causes us to coincidentally
anatofuz
parents:
diff changeset
58 // accept the first case below but reject the second two.
anatofuz
parents:
diff changeset
59 #define PASTE(A, B) A ## B
anatofuz
parents:
diff changeset
60 extern int PASTE(\, u00FD);
anatofuz
parents:
diff changeset
61 extern int PASTE(\u, 00FD); // expected-warning{{\u used with no following hex digits}}
anatofuz
parents:
diff changeset
62 extern int PASTE(\u0, 0FD); // expected-warning{{incomplete universal character name}}
anatofuz
parents:
diff changeset
63 #ifdef __cplusplus
anatofuz
parents:
diff changeset
64 // expected-error@-3 {{expected unqualified-id}}
anatofuz
parents:
diff changeset
65 // expected-error@-3 {{expected unqualified-id}}
anatofuz
parents:
diff changeset
66 #else
anatofuz
parents:
diff changeset
67 // expected-error@-6 {{expected identifier}}
anatofuz
parents:
diff changeset
68 // expected-error@-6 {{expected identifier}}
anatofuz
parents:
diff changeset
69 #endif
anatofuz
parents:
diff changeset
70
anatofuz
parents:
diff changeset
71
anatofuz
parents:
diff changeset
72 // A UCN produced by line splicing is valid in C99 but undefined in C++.
anatofuz
parents:
diff changeset
73 // Since undefined behavior can do anything including working as intended,
anatofuz
parents:
diff changeset
74 // we just accept it in C++ as well.;
anatofuz
parents:
diff changeset
75 #define newline_1_\u00F\
anatofuz
parents:
diff changeset
76 C 1
anatofuz
parents:
diff changeset
77 #define newline_2_\u00\
anatofuz
parents:
diff changeset
78 F\
anatofuz
parents:
diff changeset
79 C 1
anatofuz
parents:
diff changeset
80 #define newline_3_\u\
anatofuz
parents:
diff changeset
81 00\
anatofuz
parents:
diff changeset
82 FC 1
anatofuz
parents:
diff changeset
83 #define newline_4_\\
anatofuz
parents:
diff changeset
84 u00FC 1
anatofuz
parents:
diff changeset
85 #define newline_5_\\
anatofuz
parents:
diff changeset
86 u\
anatofuz
parents:
diff changeset
87 \
anatofuz
parents:
diff changeset
88 0\
anatofuz
parents:
diff changeset
89 0\
anatofuz
parents:
diff changeset
90 F\
anatofuz
parents:
diff changeset
91 C 1
anatofuz
parents:
diff changeset
92
anatofuz
parents:
diff changeset
93 #if (newline_1_\u00FC && newline_2_\u00FC && newline_3_\u00FC && \
anatofuz
parents:
diff changeset
94 newline_4_\u00FC && newline_5_\u00FC)
anatofuz
parents:
diff changeset
95 #else
anatofuz
parents:
diff changeset
96 #error "Line splicing failed to produce UCNs"
anatofuz
parents:
diff changeset
97 #endif
anatofuz
parents:
diff changeset
98
anatofuz
parents:
diff changeset
99
anatofuz
parents:
diff changeset
100 #define capital_u_\U00FC
anatofuz
parents:
diff changeset
101 // expected-warning@-1 {{incomplete universal character name}} expected-note@-1 {{did you mean to use '\u'?}} expected-warning@-1 {{whitespace}}
anatofuz
parents:
diff changeset
102 // CHECK: note: did you mean to use '\u'?
anatofuz
parents:
diff changeset
103 // CHECK-NEXT: #define capital_u_\U00FC
anatofuz
parents:
diff changeset
104 // CHECK-NEXT: {{^ \^}}
anatofuz
parents:
diff changeset
105 // CHECK-NEXT: {{^ u}}