brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · 5ffa550 Raw
91 lines · cpp
1// RUN: %clang_cc1 -fchar8_t -std=c++17 -verify %s2// RUN: %clang_cc1 -std=c++2a -verify=expected %s3// RUN: %clang_cc1 -std=c++2a -verify=expected -fno-signed-char %s4 5 6char8_t a = u8'a';7char8_t b[] = u8"foo";8char8_t c = 'a';9char8_t d[] = "foo"; // expected-error {{initializing 'char8_t' array with plain string literal}} expected-note {{add 'u8' prefix}}10 11char e = u8'a';12char g = 'a';13char h[] = "foo";14 15unsigned char i[] = u8"foo";16unsigned char j[] = { u8"foo" };17char k[] = u8"foo";18char l[] = { u8"foo" };19signed char m[] = u8"foo"; // expected-error {{initialization of char array with UTF-8 string literal is not permitted}}20signed char n[] = { u8"foo" }; // expected-error {{cannot initialize an array element of type 'signed char' with an lvalue of type 'const char8_t[4]'}}21 22const unsigned char* uptr = u8"foo"; // expected-error {{cannot initialize}}23const signed char* sptr = u8"foo"; // expected-error {{cannot initialize}}24const char* ptr = u8"foo"; // expected-error {{cannot initialize}}25 26template <typename T>27void check_values() {28  constexpr T c[] = {0, static_cast<T>(0xFF), 0x42};29  constexpr T a[] = u8"\x00\xFF\x42";30 31  static_assert(a[0] == c[0]);32  static_assert(a[1] == c[1]);33  static_assert(a[2] == c[2]);34}35 36void call_check_values() {37  check_values<char>();38  check_values<unsigned char>();39}40 41void disambig() {42  char8_t (a) = u8'x';43}44 45void operator""_a(char);46void operator""_a(const char*, decltype(sizeof(0)));47 48void test_udl1() {49  int &x = u8'a'_a; // expected-error {{no matching literal operator}}50  float &y = u8"a"_a; // expected-error {{no matching literal operator}}51}52 53int &operator""_a(char8_t);54float &operator""_a(const char8_t*, decltype(sizeof(0)));55 56void test_udl2() {57  int &x = u8'a'_a;58  float &y = u8"a"_a;59}60 61template<typename E, typename T> void check(T &&t) {62  using Check = E;63  using Check = T;64}65void check_deduction() {66  check<char8_t>(u8'a');67  check<const char8_t(&)[5]>(u8"a\u1000");68}69 70static_assert(sizeof(char8_t) == 1);71static_assert(char8_t(-1) > 0);72static_assert(u8"\u0080"[0] > 0);73 74namespace ambiguous {75 76struct A {77	char8_t s[10];78};79struct B {80  char s[10];81};82 83void f(A); // expected-note {{candidate}}84void f(B); // expected-note {{candidate}}85 86int test() {87  f({u8"foo"}); // expected-error {{call to 'f' is ambiguous}}88}89 90}91