diff options
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/CodeGenCXX/char8_t.cpp | 8 | ||||
-rw-r--r-- | clang/test/Lexer/char8_t.cpp | 17 | ||||
-rw-r--r-- | clang/test/Lexer/cxx-features.cpp | 7 | ||||
-rw-r--r-- | clang/test/SemaCXX/char8_t.cpp | 44 |
4 files changed, 76 insertions, 0 deletions
diff --git a/clang/test/CodeGenCXX/char8_t.cpp b/clang/test/CodeGenCXX/char8_t.cpp new file mode 100644 index 00000000000..e4dba584a6e --- /dev/null +++ b/clang/test/CodeGenCXX/char8_t.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -std=c++17 -emit-llvm -fchar8_t -triple x86_64-linux %s -o - | FileCheck %s + +// CHECK: define void @_Z1fDu( +void f(char8_t c) {} + +// CHECK: define void @_Z1gIiEvDTplplcvT__ELA4_KDuELDu114EE +template<typename T> void g(decltype(T() + u8"foo" + u8'r')) {} +template void g<int>(const char8_t*); diff --git a/clang/test/Lexer/char8_t.cpp b/clang/test/Lexer/char8_t.cpp new file mode 100644 index 00000000000..20f820e2401 --- /dev/null +++ b/clang/test/Lexer/char8_t.cpp @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -std=c++2a -verify %s +// RUN: %clang_cc1 -std=c++2a -verify %s -fchar8_t + +#if defined(__cpp_char8_t) && __is_identifier(char8_t) +#error char8_t is an identifier under -fchar8_t +#endif + +#if !defined(__cpp_char8_t) && !__is_identifier(char8_t) +#error char8_t is a keyword under -fno-char8_t +#endif + +char8_t c8t; +#ifndef __cpp_char8_t +// expected-error@-2 {{unknown type}} +#else +// expected-no-diagnostics +#endif diff --git a/clang/test/Lexer/cxx-features.cpp b/clang/test/Lexer/cxx-features.cpp index a7d12e2e14f..352f08e73b3 100644 --- a/clang/test/Lexer/cxx-features.cpp +++ b/clang/test/Lexer/cxx-features.cpp @@ -6,6 +6,7 @@ // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fsized-deallocation -fconcepts-ts -DCONCEPTS_TS=1 -verify %s // RUN: %clang_cc1 -fno-rtti -fno-threadsafe-statics -verify %s -DNO_EXCEPTIONS -DNO_RTTI -DNO_THREADSAFE_STATICS -fsized-deallocation // RUN: %clang_cc1 -fcoroutines-ts -DNO_EXCEPTIONS -DCOROUTINES -verify -fsized-deallocation %s +// RUN: %clang_cc1 -fchar8_t -DNO_EXCEPTIONS -DCHAR8_T -verify -fsized-deallocation %s // expected-no-diagnostics @@ -242,3 +243,9 @@ #if defined(COROUTINES) ? check(coroutines, 201703L, 201703L, 201703L, 201703L) : check(coroutines, 0, 0, 0, 0) #error "wrong value for __cpp_coroutines" #endif + +// --- not-yet-standard features -- + +#if defined(CHAR8_T) ? check(char8_t, 201803, 201803, 201803, 201803) : check(char8_t, 0, 0, 0, 0) +#error "wrong value for __cpp_char8_t" +#endif diff --git a/clang/test/SemaCXX/char8_t.cpp b/clang/test/SemaCXX/char8_t.cpp new file mode 100644 index 00000000000..5eb3d7062d2 --- /dev/null +++ b/clang/test/SemaCXX/char8_t.cpp @@ -0,0 +1,44 @@ +// RUN: %clang_cc1 -fchar8_t -std=c++2a -verify %s + +char8_t a = u8'a'; +char8_t b[] = u8"foo"; +char8_t c = 'a'; +char8_t d[] = "foo"; // expected-error {{initializing 'char8_t' array with plain string literal}} expected-note {{add 'u8' prefix}} + +char e = u8'a'; +char f[] = u8"foo"; // expected-error {{initialization of char array with UTF-8 string literal is not permitted by '-fchar8_t'}} +char g = 'a'; +char h[] = "foo"; + +void disambig() { + char8_t (a) = u8'x'; +} + +void operator""_a(char); +void operator""_a(const char*, decltype(sizeof(0))); + +void test_udl1() { + int &x = u8'a'_a; // expected-error {{no matching literal operator}} + float &y = u8"a"_a; // expected-error {{no matching literal operator}} +} + +int &operator""_a(char8_t); +float &operator""_a(const char8_t*, decltype(sizeof(0))); + +void test_udl2() { + int &x = u8'a'_a; + float &y = u8"a"_a; +} + +template<typename E, typename T> void check(T &&t) { + using Check = E; + using Check = T; +} +void check_deduction() { + check<char8_t>(u8'a'); + check<const char8_t(&)[5]>(u8"a\u1000"); +} + +static_assert(sizeof(char8_t) == 1); +static_assert(char8_t(-1) > 0); +static_assert(u8"\u0080"[0] > 0); |