139 lines · c
1// RUN: %clang_cc1 -x c++ -std=gnu++11 -fsyntax-only -pedantic -verify=ext,expected %s2// RUN: %clang_cc1 -x c -std=gnu11 -fsyntax-only -pedantic -verify=ext,expected %s3// RUN: %clang_cc1 -x c++ -std=c++23 -fsyntax-only -pedantic -verify=cxx23,expected -Wpre-c++23-compat %s4// RUN: %clang_cc1 -x c++ -std=gnu++11 -fwchar-type=short -fno-signed-wchar -fsyntax-only -pedantic -verify=ext,expected %s5// RUN: %clang_cc1 -x c -std=gnu11 -fwchar-type=short -fno-signed-wchar -fsyntax-only -pedantic -verify=ext,expected %s6// RUN: %clang_cc1 -x c++ -std=c++17 -ftrigraphs -fsyntax-only -pedantic -verify=ext,expected -DTRIGRAPHS=1 %s7 8const char *errors =9 "\u{}" // expected-error {{delimited escape sequence cannot be empty}}10 "\u{" // expected-error {{expected '}'}}11 "\u{h}" // expected-error {{invalid digit 'h' in escape sequence}}12 "\x{}" // expected-error {{delimited escape sequence cannot be empty}}13 "\x{" // expected-error {{expected '}'}}14 "\x{h}" // expected-error {{invalid digit 'h' in escape sequence}}15 "\o{}" // expected-error {{delimited escape sequence cannot be empty}}16 "\o{" // expected-error {{expected '}'}}17 "\o" // expected-error {{expected '{' after '\o' escape sequence}}18 "\o{8}" // expected-error {{invalid digit '8' in escape sequence}}19 "\U{8}" // expected-error {{\U used with no following hex digits}}20 ;21 22void ucn(void) {23 char a = '\u{1234}'; // expected-error {{character too large for enclosing character literal type}} \24 // ext-warning {{extension}} cxx23-warning {{C++23}}25 26 unsigned b = U'\u{1234}'; // ext-warning {{extension}} cxx23-warning {{C++23}}27 28#ifdef __cplusplus29 unsigned b2 = U'\u{1}'; // ext-warning {{extension}} cxx23-warning {{C++23}}30#else31 unsigned b2 = U'\u{1}'; //expected-error {{universal character name refers to a control character}}32#endif33 34 unsigned c = U'\u{000000000001234}'; // ext-warning {{extension}} cxx23-warning {{C++23}}35 unsigned d = U'\u{111111111}'; //expected-error {{hex escape sequence out of range}}36}37 38void hex(void) {39 char a = '\x{1}'; // ext-warning {{extension}} cxx23-warning {{C++23}}40 char b = '\x{abcdegggggabc}'; // expected-error 5{{invalid digit 'g' in escape sequence}}41 char c = '\x{ff1}'; // expected-error {{hex escape sequence out of range}}42 43#if __WCHAR_MAX__ > 0xFFFF44 unsigned d = L'\x{FFFFFFFF}'; // ext-warning {{extension}} cxx23-warning {{C++23}}45 unsigned e = L'\x{100000000}'; // expected-error {{hex escape sequence out of range}}46#else47 unsigned f = L'\x{FFFF}'; // ext-warning {{extension}} cxx23-warning {{C++23}}48 unsigned g = L'\x{10000}'; // expected-error {{hex escape sequence out of range}}49#endif50 unsigned h = U'\x{FFFFFFFF}'; // ext-warning {{extension}} cxx23-warning {{C++23}}51 unsigned i = U'\x{100000000}'; // expected-error {{hex escape sequence out of range}}52}53 54void octal(void) {55 char a = '\o{1}'; // ext-warning {{extension}} cxx23-warning {{C++23}}56 char b = '\o{12345678881238}'; // expected-error 4{{invalid digit '8' in escape sequence}}57 char c = '\o{777}'; // //expected-error {{octal escape sequence out of range}}58#if __WCHAR_MAX__ > 0xFFFF59 unsigned d = L'\o{37777777777}'; // ext-warning {{extension}} cxx23-warning {{C++23}}60 unsigned e = L'\o{40000000000}'; // expected-error {{octal escape sequence out of range}}61 unsigned f = L'\o{100000000000}'; // expected-error {{octal escape sequence out of range}}62 unsigned g = L'\o{200000000000}'; // expected-error {{octal escape sequence out of range}}63#else64 unsigned d = L'\o{177777}'; // ext-warning {{extension}} cxx23-warning {{C++23}}65 unsigned e = L'\o{200000}'; // expected-error {{octal escape sequence out of range}}66#endif67}68 69void concat(void) {70 (void)"\x{" "12}"; // expected-error {{expected '}'}}71 (void)"\u{" "12}"; // expected-error {{expected '}'}}72 (void)"\o{" "12}"; // expected-error {{expected '}'}}73 74 (void)"\x{12" "}"; // expected-error {{expected '}'}}75 (void)"\u{12" "}"; // expected-error {{expected '}'}}76 (void)"\o{12" "}"; // expected-error {{expected '}'}}77}78 79void named(void) {80 char a = '\N{LOTUS}'; // expected-error{{character too large for enclosing character literal type}} \81 // ext-warning {{extension}} cxx23-warning {{C++23}}82 83 char b = '\N{DOLLAR SIGN}'; // ext-warning {{extension}} cxx23-warning {{C++23}}84 char b_ = '\N{ DOL-LAR _SIGN }'; // expected-error {{' DOL-LAR _SIGN ' is not a valid Unicode character name}} \85 // expected-note {{characters names in Unicode escape sequences are sensitive to case and whitespaces}}86 87 char c = '\N{NOTATHING}'; // expected-error {{'NOTATHING' is not a valid Unicode character name}} \88 // expected-note 5{{did you mean}}89 char d = '\N{}'; // expected-error {{delimited escape sequence cannot be empty}}90 char e = '\N{'; // expected-error {{incomplete universal character name}}91 92 unsigned f = L'\N{GREEK CAPITAL LETTER DELTA}'; // ext-warning {{extension}} cxx23-warning {{C++23}}93 94 unsigned g = u'\N{LOTUS}'; // expected-error {{character too large for enclosing character literal type}} \95 // ext-warning {{extension}} cxx23-warning {{C++23}}96 97 unsigned h = U'\N{LOTUS}'; // ext-warning {{extension}} cxx23-warning {{C++23}}98 unsigned i = u'\N{GREEK CAPITAL LETTER DELTA}'; // ext-warning {{extension}} cxx23-warning {{C++23}}99 char j = '\NN'; // expected-error {{expected '{' after '\N' escape sequence}} expected-warning {{multi-character character constant}}100 unsigned k = u'\N{LOTUS'; // expected-error {{incomplete universal character name}}101 102 const char* emoji = "\N{🤡}"; // expected-error {{'🤡' is not a valid Unicode character name}} \103 // expected-note 5{{did you mean}}104 const char* nested = "\N{\N{SPARKLE}}"; // expected-error {{'\N{SPARKLE' is not a valid Unicode character name}} \105 // expected-note 5{{did you mean}}106}107 108void separators(void) {109 (void)"\x{12'3}"; // expected-error {{invalid digit ''' in escape sequence}}110 (void)"\u{12'3}"; // expected-error {{invalid digit ''' in escape sequence}}111 (void)"\o{12'3}"; // expected-error {{invalid digit ''' in escape sequence}}112 113 '\x{12'3'}'; // expected-error {{expected '}'}}114 // expected-error@-1 2{{expected ';'}}115 // expected-warning@-2 3{{expression result unused}}116}117 118#if L'\N{GREEK CAPITAL LETTER GAMMA}' != L'Γ' // ext-warning {{extension}} cxx23-warning {{C++23}}119#error "oh no!"120#endif121 122#ifdef TRIGRAPHS123static_assert('\N??<DOLLAR SIGN??>' == '$'); // expected-warning 2{{trigraph converted}} \124 // ext-warning {{extension}} cxx23-warning {{C++23}}125#endif126 127void GH102218(void) {128 // The format specifier checking code runs the lexer with diagnostics129 // disabled. This used to crash Clang for malformed \o and \x because the130 // lexer missed a null pointer check for the diagnostics engine in that case.131 extern int printf(const char *, ...);132 printf("\o{}"); // expected-error {{delimited escape sequence cannot be empty}}133 printf("\x{}"); // expected-error {{delimited escape sequence cannot be empty}}134 135 // These cases always worked but are here for completeness.136 printf("\u{}"); // expected-error {{delimited escape sequence cannot be empty}}137 printf("\N{}"); // expected-error {{delimited escape sequence cannot be empty}}138}139