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