1 // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c11 -x c -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c2x -x c -fsyntax-only -verify %s
3 // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -fsyntax-only -verify %s
4 // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++17 -fsyntax-only -verify %s
5 // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++17 -fsyntax-only -fchar8_t -verify %s
6 // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++20 -fsyntax-only -verify %s
7 // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++20 -fsyntax-only -fno-char8_t -verify %s
9 int array0
[u
'ñ' == u
'\xf1'? 1 : -1];
10 int array1
['\xF1' != u
'\xf1'? 1 : -1];
11 int array1
['ñ' != u
'\xf1'? 1 : -1]; // expected-error {{character too large for enclosing character literal type}}
12 #if __cplusplus > 201402L
13 char a
= u8
'ñ'; // expected-error {{character too large for enclosing character literal type}}
14 char b
= u8
'\x80'; // ok
15 char c
= u8
'\u0080'; // expected-error {{character too large for enclosing character literal type}}
16 char d
= u8
'\u1234'; // expected-error {{character too large for enclosing character literal type}}
17 char e
= u8
'ሴ'; // expected-error {{character too large for enclosing character literal type}}
18 char f
= u8
'ab'; // expected-error {{Unicode character literals may not contain multiple characters}}
19 #elif __STDC_VERSION__ >= 202311L
20 char a
= u8
'ñ'; // expected-error {{character too large for enclosing character literal type}}
21 char b
= u8
'\x80'; // ok
22 char c
= u8
'\u0000'; // ok
23 char d
= u8
'\u1234'; // expected-error {{character too large for enclosing character literal type}}
24 char e
= u8
'ሴ'; // expected-error {{character too large for enclosing character literal type}}
25 char f
= u8
'ab'; // expected-error {{Unicode character literals may not contain multiple characters}}
34 // UTF-8 character literals are enabled in C++17 and later. If `-fchar8_t` is not enabled
35 // (as is the case in C++17), then UTF-8 character literals may produce signed or
36 // unsigned values depending on whether char is a signed type. If `-fchar8_t` is enabled
37 // (which is the default behavior for C++20), then UTF-8 character literals always
38 // produce unsigned values. The tests below depend on the target having a signed
39 // 8-bit char so that '\xff' produces a negative value.
40 #if __cplusplus >= 201703L
41 # if !defined(__cpp_char8_t)
42 # if !(u8'\xff' == '\xff')
43 # error UTF-8 character value did not match ordinary character literal; this is unexpected
46 # if u8'\xff' == '\xff' // expected-warning {{right side of operator converted from negative value to unsigned}}
47 # error UTF-8 character value matched ordinary character literal; this is unexpected
52 /// In C23, u8 char literals are always unsigned.
53 #if __STDC_VERSION__ >= 202311L
54 # if u8'\xff' == '\xff'// expected-warning {{right side of operator converted from negative value to unsigned}}
55 # error u8 char literal is not unsigned