brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.1 KiB · 4db7a2e Raw
58 lines · cpp
1// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c11 -x c -fsyntax-only -verify %s2// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c2x -x c -fsyntax-only -verify %s3// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -fsyntax-only -verify %s4// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++17 -fsyntax-only -verify %s5// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++17 -fsyntax-only -fchar8_t -verify %s6// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++20 -fsyntax-only -verify %s7// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++20 -fsyntax-only -fno-char8_t -verify %s8 9int array0[u'ñ' == u'\xf1'? 1 : -1];10int array1['\xF1' !=  u'\xf1'? 1 : -1];11int array1['ñ' !=  u'\xf1'? 1 : -1]; // expected-error {{character too large for enclosing character literal type}}12#if __cplusplus > 201402L13char a = u8'ñ'; // expected-error {{character too large for enclosing character literal type}}14char b = u8'\x80'; // ok15char c = u8'\u0080'; // expected-error {{character too large for enclosing character literal type}}16char d = u8'\u1234'; // expected-error {{character too large for enclosing character literal type}}17char e = u8'ሴ'; // expected-error {{character too large for enclosing character literal type}}18char f = u8'ab'; // expected-error {{Unicode character literals may not contain multiple characters}}19#elif __STDC_VERSION__ >= 202311L20char a = u8'ñ';      // expected-error {{character too large for enclosing character literal type}}21char b = u8'\x80';   // ok22char c = u8'\u0000'; // ok23char d = u8'\u1234'; // expected-error {{character too large for enclosing character literal type}}24char e = u8'ሴ';      // expected-error {{character too large for enclosing character literal type}}25char f = u8'ab';     // expected-error {{Unicode character literals may not contain multiple characters}}26_Static_assert(27    _Generic(u8'a',28             default : 0,29             unsigned char : 1),30    "Surprise!");31#endif32 33 34// UTF-8 character literals are enabled in C++17 and later. If `-fchar8_t` is not enabled35// (as is the case in C++17), then UTF-8 character literals may produce signed or36// unsigned values depending on whether char is a signed type. If `-fchar8_t` is enabled37// (which is the default behavior for C++20), then UTF-8 character literals always38// produce unsigned values. The tests below depend on the target having a signed39// 8-bit char so that '\xff' produces a negative value.40#if __cplusplus >= 201703L41#  if !defined(__cpp_char8_t)42#    if !(u8'\xff' == '\xff')43#      error UTF-8 character value did not match ordinary character literal; this is unexpected44#    endif45#  else46#    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 unexpected48#    endif49#  endif50#endif51 52/// In C23, u8 char literals are always unsigned.53#if __STDC_VERSION__ >= 202311L54#  if u8'\xff' == '\xff'// expected-warning {{right side of operator converted from negative value to unsigned}}55#    error u8 char literal is not unsigned56#  endif57#endif58