Richard Smith | 28ddb91 | 2018-11-14 21:04:34 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fchar8_t -std=c++17 -verify %s |
| 2 | // RUN: %clang_cc1 -std=c++2a -verify %s |
Richard Smith | 3a8244d | 2018-05-01 05:02:45 +0000 | [diff] [blame] | 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'; |
Richard Smith | 28ddb91 | 2018-11-14 21:04:34 +0000 | [diff] [blame] | 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 |
Richard Smith | 3a8244d | 2018-05-01 05:02:45 +0000 | [diff] [blame] | 16 | char g = 'a'; |
| 17 | char h[] = "foo"; |
| 18 | |
| 19 | void disambig() { |
| 20 | char8_t (a) = u8'x'; |
| 21 | } |
| 22 | |
| 23 | void operator""_a(char); |
| 24 | void operator""_a(const char*, decltype(sizeof(0))); |
| 25 | |
| 26 | void 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 | |
| 34 | void test_udl2() { |
| 35 | int &x = u8'a'_a; |
| 36 | float &y = u8"a"_a; |
| 37 | } |
| 38 | |
| 39 | template<typename E, typename T> void check(T &&t) { |
| 40 | using Check = E; |
| 41 | using Check = T; |
| 42 | } |
| 43 | void 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); |