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