| 1 |
// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++03 -Wfour-char-constants -fsyntax-only -verify=cxx03,expected %s |
| 2 |
// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -Wfour-char-constants -fsyntax-only -verify=cxx,expected %s |
| 3 |
// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++17 -Wfour-char-constants -fsyntax-only -verify=cxx,expected %s |
| 4 |
// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++20 -Wfour-char-constants -fsyntax-only -verify=cxx,expected %s |
| 5 |
// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c11 -x c -Wfour-char-constants -fsyntax-only -verify=c11,expected %s |
| 6 |
// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c2x -x c -Wfour-char-constants -fsyntax-only -verify=c2x,expected %s |
| 7 |
|
| 8 |
#ifndef __cplusplus |
| 9 |
typedef __WCHAR_TYPE__ wchar_t; |
| 10 |
typedef __CHAR16_TYPE__ char16_t; |
| 11 |
typedef __CHAR32_TYPE__ char32_t; |
| 12 |
#endif |
| 13 |
|
| 14 |
int a = 'ab'; // expected-warning {{multi-character character constant}} |
| 15 |
int b = '\xFF\xFF'; // expected-warning {{multi-character character constant}} |
| 16 |
int c = 'APPS'; // expected-warning {{multi-character character constant}} |
| 17 |
|
| 18 |
char d = '⌘'; // expected-error {{character too large for enclosing character literal type}} |
| 19 |
char e = '\u2318'; // expected-error {{character too large for enclosing character literal type}} |
| 20 |
|
| 21 |
#if !defined(__cplusplus) || __cplusplus > 201100L |
| 22 |
#ifdef __cplusplus |
| 23 |
auto f = '\xE2\x8C\x98'; // expected-warning {{multi-character character constant}} |
| 24 |
#endif |
| 25 |
|
| 26 |
char16_t g = u'ab'; // expected-error {{Unicode character literals may not contain multiple characters}} |
| 27 |
char16_t h = u'\U0010FFFD'; // expected-error {{character too large for enclosing character literal type}} |
| 28 |
|
| 29 |
wchar_t i = L'ab'; // expected-error {{wide character literals may not contain multiple characters}} |
| 30 |
|
| 31 |
wchar_t j = L'\U0010FFFD'; |
| 32 |
|
| 33 |
char32_t k = U'\U0010FFFD'; |
| 34 |
|
| 35 |
char l = 'Ø'; // expected-error {{character too large for enclosing character literal type}} |
| 36 |
char m = '👿'; // expected-error {{character too large for enclosing character literal type}} |
| 37 |
|
| 38 |
char32_t n = U'ab'; // expected-error {{Unicode character literals may not contain multiple characters}} |
| 39 |
char16_t o = '👽'; // expected-error {{character too large for enclosing character literal type}} |
| 40 |
|
| 41 |
char16_t p[2] = u"\U0000FFFF"; |
| 42 |
char16_t q[2] = u"\U00010000"; |
| 43 |
#ifdef __cplusplus |
| 44 |
// expected-error@-2 {{too long}} |
| 45 |
#endif |
| 46 |
|
| 47 |
// UTF-8 character literal code point ranges. |
| 48 |
#if __cplusplus >= 201703L || __STDC_VERSION__ >= 201710L |
| 49 |
_Static_assert(u8'\U00000000' == 0x00, ""); // c11-error {{universal character name refers to a control character}} |
| 50 |
_Static_assert(u8'\U0000007F' == 0x7F, ""); // c11-error {{universal character name refers to a control character}} |
| 51 |
_Static_assert(u8'\U00000080', ""); // c11-error {{universal character name refers to a control character}} |
| 52 |
// cxx-error@-1 {{character too large for enclosing character literal type}} |
| 53 |
// c2x-error@-2 {{character too large for enclosing character literal type}} |
| 54 |
_Static_assert((unsigned char)u8'\xFF' == (unsigned char)0xFF, ""); |
| 55 |
#endif |
| 56 |
|
| 57 |
// UTF-8 string literal code point ranges. |
| 58 |
_Static_assert(u8"\U00000000"[0] == 0x00, ""); // c11-error {{universal character name refers to a control character}} |
| 59 |
_Static_assert(u8"\U0000007F"[0] == 0x7F, ""); // c11-error {{universal character name refers to a control character}} |
| 60 |
_Static_assert((unsigned char)u8"\U00000080"[0] == (unsigned char)0xC2, ""); // c11-error {{universal character name refers to a control character}} |
| 61 |
_Static_assert((unsigned char)u8"\U00000080"[1] == (unsigned char)0x80, ""); // c11-error {{universal character name refers to a control character}} |
| 62 |
_Static_assert((unsigned char)u8"\U000007FF"[0] == (unsigned char)0xDF, ""); |
| 63 |
_Static_assert((unsigned char)u8"\U000007FF"[1] == (unsigned char)0xBF, ""); |
| 64 |
_Static_assert((unsigned char)u8"\U00000800"[0] == (unsigned char)0xE0, ""); |
| 65 |
_Static_assert((unsigned char)u8"\U00000800"[1] == (unsigned char)0xA0, ""); |
| 66 |
_Static_assert((unsigned char)u8"\U00000800"[2] == (unsigned char)0x80, ""); |
| 67 |
_Static_assert(u8"\U0000D800"[0], ""); // expected-error {{invalid universal character}} |
| 68 |
_Static_assert(u8"\U0000DFFF"[0], ""); // expected-error {{invalid universal character}} |
| 69 |
_Static_assert((unsigned char)u8"\U0000FFFF"[0] == (unsigned char)0xEF, ""); |
| 70 |
_Static_assert((unsigned char)u8"\U0000FFFF"[1] == (unsigned char)0xBF, ""); |
| 71 |
_Static_assert((unsigned char)u8"\U0000FFFF"[2] == (unsigned char)0xBF, ""); |
| 72 |
_Static_assert((unsigned char)u8"\U00010000"[0] == (unsigned char)0xF0, ""); |
| 73 |
_Static_assert((unsigned char)u8"\U00010000"[1] == (unsigned char)0x90, ""); |
| 74 |
_Static_assert((unsigned char)u8"\U00010000"[2] == (unsigned char)0x80, ""); |
| 75 |
_Static_assert((unsigned char)u8"\U00010000"[3] == (unsigned char)0x80, ""); |
| 76 |
_Static_assert((unsigned char)u8"\U0010FFFF"[0] == (unsigned char)0xF4, ""); |
| 77 |
_Static_assert((unsigned char)u8"\U0010FFFF"[1] == (unsigned char)0x8F, ""); |
| 78 |
_Static_assert((unsigned char)u8"\U0010FFFF"[2] == (unsigned char)0xBF, ""); |
| 79 |
_Static_assert((unsigned char)u8"\U0010FFFF"[3] == (unsigned char)0xBF, ""); |
| 80 |
_Static_assert(u8"\U00110000"[0], ""); // expected-error {{invalid universal character}} |
| 81 |
|
| 82 |
#if !defined(__STDC_UTF_16__) |
| 83 |
#error __STDC_UTF_16__ is not defined. |
| 84 |
#endif |
| 85 |
#if __STDC_UTF_16__ != 1 |
| 86 |
#error __STDC_UTF_16__ has the wrong value. |
| 87 |
#endif |
| 88 |
|
| 89 |
// UTF-16 character literal code point ranges. |
| 90 |
_Static_assert(u'\U00000000' == 0x0000, ""); // c11-error {{universal character name refers to a control character}} |
| 91 |
_Static_assert(u'\U0000D800', ""); // expected-error {{invalid universal character}} |
| 92 |
_Static_assert(u'\U0000DFFF', ""); // expected-error {{invalid universal character}} |
| 93 |
_Static_assert(u'\U0000FFFF' == 0xFFFF, ""); |
| 94 |
_Static_assert(u'\U00010000', ""); // expected-error {{character too large for enclosing character literal type}} |
| 95 |
|
| 96 |
// UTF-16 string literal code point ranges. |
| 97 |
_Static_assert(u"\U00000000"[0] == 0x0000, ""); // c11-error {{universal character name refers to a control character}} |
| 98 |
_Static_assert(u"\U0000D800"[0], ""); // expected-error {{invalid universal character}} |
| 99 |
_Static_assert(u"\U0000DFFF"[0], ""); // expected-error {{invalid universal character}} |
| 100 |
_Static_assert(u"\U0000FFFF"[0] == 0xFFFF, ""); |
| 101 |
_Static_assert(u"\U00010000"[0] == 0xD800, ""); |
| 102 |
_Static_assert(u"\U00010000"[1] == 0xDC00, ""); |
| 103 |
_Static_assert(u"\U0010FFFF"[0] == 0xDBFF, ""); |
| 104 |
_Static_assert(u"\U0010FFFF"[1] == 0xDFFF, ""); |
| 105 |
_Static_assert(u"\U00110000"[0], ""); // expected-error {{invalid universal character}} |
| 106 |
|
| 107 |
#if !defined(__STDC_UTF_32__) |
| 108 |
#error __STDC_UTF_32__ is not defined. |
| 109 |
#endif |
| 110 |
#if __STDC_UTF_32__ != 1 |
| 111 |
#error __STDC_UTF_32__ has the wrong value. |
| 112 |
#endif |
| 113 |
|
| 114 |
// UTF-32 character literal code point ranges. |
| 115 |
_Static_assert(U'\U00000000' == 0x00000000, ""); // c11-error {{universal character name refers to a control character}} |
| 116 |
_Static_assert(U'\U0010FFFF' == 0x0010FFFF, ""); |
| 117 |
_Static_assert(U'\U00110000', ""); // expected-error {{invalid universal character}} |
| 118 |
|
| 119 |
// UTF-32 string literal code point ranges. |
| 120 |
_Static_assert(U"\U00000000"[0] == 0x00000000, ""); // c11-error {{universal character name refers to a control character}} |
| 121 |
_Static_assert(U"\U0000D800"[0], ""); // expected-error {{invalid universal character}} |
| 122 |
_Static_assert(U"\U0000DFFF"[0], ""); // expected-error {{invalid universal character}} |
| 123 |
_Static_assert(U"\U0010FFFF"[0] == 0x0010FFFF, ""); |
| 124 |
_Static_assert(U"\U00110000"[0], ""); // expected-error {{invalid universal character}} |
| 125 |
|
| 126 |
#endif // !defined(__cplusplus) || __cplusplus > 201100L |
| 127 |
|
| 128 |
_Static_assert('\u0024' == '$', ""); |
| 129 |
_Static_assert('\u0040' == '@', ""); |
| 130 |
_Static_assert('\u0060' == '`', ""); |
| 131 |
|
| 132 |
_Static_assert('\u0061' == 'a', ""); // c11-error {{character 'a' cannot be specified by a universal character name}} \ |
| 133 |
// cxx03-error {{character 'a' cannot be specified by a universal character name}} |
| 134 |
_Static_assert('\u0000' == '\0', ""); // c11-error {{universal character name refers to a control character}} \ |
| 135 |
// cxx03-error {{universal character name refers to a control character}} |