1 // RUN: %clang_cc1 -fchar8_t -std=c++17 -verify %s 2 // RUN: %clang_cc1 -std=c++2a -verify %s 3 4 char8_t a = u8'a'; 5 char8_t b[] = u8"foo"; 6 char8_t c = 'a'; 7 char8_t d[] = "foo"; // expected-error {{initializing 'char8_t' array with plain string literal}} expected-note {{add 'u8' prefix}} 8 9 char e = u8'a'; 10 char f[] = u8"foo"; 11 #if __cplusplus <= 201703L 12 // expected-error@-2 {{initialization of char array with UTF-8 string literal is not permitted by '-fchar8_t'}} 13 #else 14 // expected-error@-4 {{ISO C++20 does not permit initialization of char array with UTF-8 string literal}} 15 #endif 16 char g = 'a'; 17 char h[] = "foo"; 18 disambig()19void disambig() { 20 char8_t (a) = u8'x'; 21 } 22 23 void operator""_a(char); 24 void operator""_a(const char*, decltype(sizeof(0))); 25 test_udl1()26void test_udl1() { 27 int &x = u8'a'_a; // expected-error {{no matching literal operator}} 28 float &y = u8"a"_a; // expected-error {{no matching literal operator}} 29 } 30 31 int &operator""_a(char8_t); 32 float &operator""_a(const char8_t*, decltype(sizeof(0))); 33 test_udl2()34void test_udl2() { 35 int &x = u8'a'_a; 36 float &y = u8"a"_a; 37 } 38 check(T && t)39template<typename E, typename T> void check(T &&t) { 40 using Check = E; 41 using Check = T; 42 } check_deduction()43void check_deduction() { 44 check<char8_t>(u8'a'); 45 check<const char8_t(&)[5]>(u8"a\u1000"); 46 } 47 48 static_assert(sizeof(char8_t) == 1); 49 static_assert(char8_t(-1) > 0); 50 static_assert(u8"\u0080"[0] > 0); 51