Clang Project

clang_source_code/test/SemaCXX/char8_t.cpp
1// RUN: %clang_cc1 -fchar8_t -std=c++17 -verify %s
2// RUN: %clang_cc1 -std=c++2a -verify %s
3
4char8_t a = u8'a';
5char8_t b[] = u8"foo";
6char8_t c = 'a';
7char8_t d[] = "foo"; // expected-error {{initializing 'char8_t' array with plain string literal}} expected-note {{add 'u8' prefix}}
8
9char e = u8'a';
10char 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
16char g = 'a';
17char h[] = "foo";
18
19void disambig() {
20  char8_t (a) = u8'x';
21}
22
23void operator""_a(char);
24void operator""_a(const char*, decltype(sizeof(0)));
25
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
31int &operator""_a(char8_t);
32float &operator""_a(const char8_t*, decltype(sizeof(0)));
33
34void test_udl2() {
35  int &x = u8'a'_a;
36  float &y = u8"a"_a;
37}
38
39template<typename E, typename T> void check(T &&t) {
40  using Check = E;
41  using Check = T;
42}
43void check_deduction() {
44  check<char8_t>(u8'a');
45  check<const char8_t(&)[5]>(u8"a\u1000");
46}
47
48static_assert(sizeof(char8_t) == 1);
49static_assert(char8_t(-1) > 0);
50static_assert(u8"\u0080"[0] > 0);
51