| 1 |
// RUN: %clang_cc1 -x c -std=c2x -fsyntax-only -verify %s |
| 2 |
// RUN: %clang_cc1 -x c -std=c2x -E -DPP_ONLY=1 %s | FileCheck %s --strict-whitespace |
| 3 |
|
| 4 |
/* WG14 N2836: Clang 15 |
| 5 |
* Identifier Syntax using Unicode Standard Annex 31 |
| 6 |
*/ |
| 7 |
|
| 8 |
/* WG14 N2939: Clang 15 |
| 9 |
* Identifier Syntax Fixes |
| 10 |
*/ |
| 11 |
|
| 12 |
// Some of the tests below are derived from clang/test/Lexer/unicode.c. |
| 13 |
|
| 14 |
// This file contains Unicode characters; please do not "fix" them! |
| 15 |
|
| 16 |
// No diagnostics for pragma directives. |
| 17 |
#pragma mark ยกUnicode! |
| 18 |
|
| 19 |
// lone non-identifier characters are allowed in preprocessing. |
| 20 |
#define COPYRIGHT Copyright ยฉ 2012 |
| 21 |
#define XSTR(X) #X |
| 22 |
#define STR(X) XSTR(X) |
| 23 |
|
| 24 |
static const char *copyright = STR(COPYRIGHT); // no-warning |
| 25 |
// CHECK: static const char *copyright = "Copyright ยฉ {{2012}}"; |
| 26 |
|
| 27 |
#if PP_ONLY |
| 28 |
COPYRIGHT |
| 29 |
// CHECK: Copyright ยฉ {{2012}} |
| 30 |
#endif |
| 31 |
|
| 32 |
// The characters in the following identifiers are no longer valid as either |
| 33 |
// start or continuation characters as of C23. These are taken from section 1 |
| 34 |
// of N2836. |
| 35 |
extern int \N{CONSTRUCTION WORKER}; // expected-error {{expected identifier or '('}} |
| 36 |
extern int X\N{CONSTRUCTION WORKER}; // expected-error {{character <U+1F477> not allowed in an identifier}} |
| 37 |
extern int \U0001F477; // expected-error {{expected identifier or '('}} |
| 38 |
extern int X\U0001F477; // expected-error {{character <U+1F477> not allowed in an identifier}} |
| 39 |
extern int ๐ท; // expected-error {{unexpected character <U+1F477>}} \ |
| 40 |
// expected-warning {{declaration does not declare anything}} |
| 41 |
extern int X๐ท; // expected-error {{character <U+1F477> not allowed in an identifier}} |
| 42 |
extern int ๐; // expected-error {{unexpected character <U+1F550>}} \ |
| 43 |
// expected-warning {{declaration does not declare anything}} |
| 44 |
extern int X๐; // expected-error {{character <U+1F550> not allowed in an identifier}} |
| 45 |
extern int ๐; // expected-error {{unexpected character <U+1F480>}} \ |
| 46 |
// expected-warning {{declaration does not declare anything}} |
| 47 |
extern int X๐; // expected-error {{character <U+1F480> not allowed in an identifier}} |
| 48 |
extern int ๐; // expected-error {{unexpected character <U+1F44A>}} \ |
| 49 |
// expected-warning {{declaration does not declare anything}} |
| 50 |
extern int X๐; // expected-error {{character <U+1F44A> not allowed in an identifier}} |
| 51 |
extern int ๐; // expected-error {{unexpected character <U+1F680>}} \ |
| 52 |
// expected-warning {{declaration does not declare anything}} |
| 53 |
extern int X๐; // expected-error {{character <U+1F680> not allowed in an identifier}} |
| 54 |
extern int ๐; // expected-error {{unexpected character <U+1F600>}} \ |
| 55 |
// expected-warning {{declaration does not declare anything}} |
| 56 |
extern int X๐; // expected-error {{character <U+1F600> not allowed in an identifier}} |
| 57 |
|
| 58 |
// The characters in the following identifiers are not allowed as start |
| 59 |
// characters, but are allowed as continuation characters. |
| 60 |
extern int \N{ARABIC-INDIC DIGIT ZERO}; // expected-error {{expected identifier or '('}} |
| 61 |
extern int X\N{ARABIC-INDIC DIGIT ZERO}; |
| 62 |
extern int \u0661; // expected-error {{expected identifier or '('}} |
| 63 |
extern int X\u0661; |
| 64 |
extern int ูข; // expected-error {{character <U+0662> not allowed at the start of an identifier}} \\ |
| 65 |
// expected-warning {{declaration does not declare anything}} |
| 66 |
extern int Xู ; |
| 67 |
|
| 68 |
// The characters in the following identifiers are not valid start or |
| 69 |
// continuation characters in the standard, but are accepted as a conforming |
| 70 |
// extension. |
| 71 |
extern int \N{SUPERSCRIPT ZERO}; // expected-error {{expected identifier or '('}} |
| 72 |
extern int X\N{SUPERSCRIPT ZERO}; // expected-warning {{mathematical notation character <U+2070> in an identifier is a Clang extension}} |
| 73 |
extern int \u00B9; // expected-error {{expected identifier or '('}} |
| 74 |
extern int X\u00B9; // expected-warning {{mathematical notation character <U+00B9> in an identifier is a Clang extension}} |
| 75 |
extern int ยฒ; // expected-error {{character <U+00B2> not allowed at the start of an identifier}} \\ |
| 76 |
// expected-warning {{declaration does not declare anything}} |
| 77 |
extern int Xยฒ; // expected-warning {{mathematical notation character <U+00B2> in an identifier is a Clang extension}} |
| 78 |
extern int \N{PARTIAL DIFFERENTIAL}; // expected-warning {{mathematical notation character <U+2202> in an identifier is a Clang extension}} |
| 79 |
extern int X\N{PARTIAL DIFFERENTIAL}; // expected-warning {{mathematical notation character <U+2202> in an identifier is a Clang extension}} |
| 80 |
extern int \u2207; // expected-warning {{mathematical notation character <U+2207> in an identifier is a Clang extension}} |
| 81 |
extern int X\u2207; // expected-warning {{mathematical notation character <U+2207> in an identifier is a Clang extension}} |
| 82 |
extern int โ; // expected-warning {{mathematical notation character <U+221E> in an identifier is a Clang extension}} |
| 83 |
extern int Xโ; // expected-warning {{mathematical notation character <U+221E> in an identifier is a Clang extension}} |