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