diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2018-11-14 21:04:34 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2018-11-14 21:04:34 +0000 |
commit | 761a1b5dc47fc195760dd66b6cfdea3924ca3af8 (patch) | |
tree | e7b9a05594ae498f2295805cd5dd76d9ffc8fdf5 /test/SemaCXX/cxx2a-compat.cpp | |
parent | 52daf3b92d0db0617bdc8d4125aaed5e4abe02db (diff) |
[c++20] Implement P0482R6: enable -fchar8_t by default in C++20 mode.
This unfortunately results in a substantial breaking change when
switching to C++20, but it's not yet clear what / how much we should
do about that. We may want to add a compatibility conversion from
u8 string literals to const char*, similar to how C++98 provided a
compatibility conversion from string literals to non-const char*,
but that's not handled by this patch.
The feature can be disabled in C++20 mode with -fno-char8_t.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@346892 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX/cxx2a-compat.cpp')
-rw-r--r-- | test/SemaCXX/cxx2a-compat.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/SemaCXX/cxx2a-compat.cpp b/test/SemaCXX/cxx2a-compat.cpp index 53043d67fb..d51f1e6aab 100644 --- a/test/SemaCXX/cxx2a-compat.cpp +++ b/test/SemaCXX/cxx2a-compat.cpp @@ -21,3 +21,19 @@ B b2 = {1, 2, 3, 4}; #else // expected-error@-4 2{{no viable conversion from 'int' to 'A'}} #endif + +// Essentially any use of a u8 string literal in C++<=17 is broken by C++20. +// Just warn on all such string literals. +struct string { string(const char*); }; // expected-note 0+{{candidate}} +char u8arr[] = u8"hello"; +const char *u8ptr = "wo" u8"rld"; +string u8str = u8"test" u8"test"; +#if __cplusplus <= 201703L +// expected-warning@-4 {{type of UTF-8 string literal will change}} expected-note@-4 {{remove 'u8' prefix}} +// expected-warning@-4 {{type of UTF-8 string literal will change}} expected-note@-4 {{remove 'u8' prefix}} +// expected-warning@-4 {{type of UTF-8 string literal will change}} expected-note@-4 {{remove 'u8' prefix}} +#else +// expected-error@-8 {{ISO C++20 does not permit initialization of char array with UTF-8 string literal}} +// expected-error@-8 {{cannot initialize a variable of type 'const char *' with an lvalue of type 'const char8_t [6]'}} +// expected-error@-8 {{no viable conversion from 'const char8_t [9]' to 'string'}} +#endif |