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