165 lines · c
1// RUN: %clang_cc1 %s -fsyntax-only -std=c99 -pedantic -verify=expected,ext -Wundef -DTRIGRAPHS=12// RUN: %clang_cc1 %s -fsyntax-only -std=c23 -pedantic -verify=expected,ext -Wundef -ftrigraphs -DTRIGRAPHS=13// RUN: %clang_cc1 %s -fsyntax-only -x c++ -pedantic -verify=expected,ext -Wundef -fno-trigraphs4// RUN: %clang_cc1 %s -fsyntax-only -x c++ -std=c++23 -pedantic -ftrigraphs -DTRIGRAPHS=1 -verify=expected,cxx23 -Wundef -Wpre-c++23-compat5// RUN: %clang_cc1 %s -fsyntax-only -x c++ -pedantic -verify=expected,ext -Wundef -ftrigraphs -DTRIGRAPHS=16// RUN: not %clang_cc1 %s -fsyntax-only -std=c99 -pedantic -Wundef 2>&1 | FileCheck -strict-whitespace %s7 8#define \u00FC9#define a\u00FD() 010#ifndef \u00FC11#error "This should never happen"12#endif13 14#if a\u00FD()15#error "This should never happen"16#endif17 18#if a\U000000FD()19#error "This should never happen"20#endif21 22#if a\u{FD}() // ext-warning {{extension}} cxx23-warning {{before C++23}}23#error "This should never happen"24#endif25 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#endif28#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#endif30#if \U0001000 // expected-warning{{incomplete universal character name; treating as '\' followed by identifier}} expected-error {{invalid token at start of a preprocessor expression}}31#endif32 33// Make sure we reject disallowed UCNs34#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#endif49 50 51#define \u0110 1 / 052#if \u0110 // expected-error {{division by zero in preprocessor expression}}53#endif54 55#define STRINGIZE(X) # X56 57extern 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 are61// formed before directives are parsed.62// expected-error@+4 {{character 'a' cannot be specified by a universal character name}}63#if 064#define \ufffe // okay65#define \U10000000 // okay66#define \u0061 // error, but -verify only looks at comments outside #if 067#endif68 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 coincidentally72// accept the first case below but reject the second two.73#define PASTE(A, B) A ## B74extern int PASTE(\, u00FD);75extern int PASTE(\u, 00FD); // expected-warning{{\u used with no following hex digits}}76extern int PASTE(\u0, 0FD); // expected-warning{{incomplete universal character name}}77#ifdef __cplusplus78// expected-error@-3 {{expected unqualified-id}}79// expected-error@-3 {{expected unqualified-id}}80#else81// expected-error@-6 {{expected identifier}}82// expected-error@-6 {{expected identifier}}83#endif84 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\90C 191#define newline_2_\u00\92F\93C 194#define newline_3_\u\9500\96FC 197#define newline_4_\\98u00FC 199#define newline_5_\\100u\101\1020\1030\104F\105C 1106 107#if (newline_1_\u00FC && newline_2_\u00FC && newline_3_\u00FC && \108 newline_4_\u00FC && newline_5_\u00FC)109#else110#error "Line splicing failed to produce UCNs"111#endif112 113 114#define capital_u_\U00FC115// 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##B139int CONCAT(\N{GREEK140, CAPITALLETTERALPHA});141// expected-error@-2 {{expected}} \142// expected-warning@-2 {{incomplete delimited universal character name}}143 144int \N{\145LATIN CAPITAL LETTER A WITH GRAVE};146//ext-warning@-2 {{extension}} cxx23-warning@-2 {{before C++23}}147 148#ifdef TRIGRAPHS149int \N??<GREEK CAPITAL LETTER ALPHA??> = 0; // cxx23-warning {{before C++23}} \150 //ext-warning {{extension}}\151 // expected-warning 2{{trigraph converted}}152 153int a\N{LATIN CAPITAL LETTER A WITH GRAVE??>; // expected-warning {{trigraph converted}}154#endif155 156#ifndef TRIGRAPHS157int 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#endif162 163// GH64161164int A\N{LEFT-TO-RIGHT OVERRIDE}; // expected-error {{character <U+202D> not allowed in an identifier}}165