diff options
Diffstat (limited to 'gcc/testsuite/g++.dg/cpp0x')
6 files changed, 136 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-wstring2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-wstring2.C index 4055e0ee8ec..b878918a9f3 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-wstring2.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-wstring2.C @@ -4,3 +4,4 @@ constexpr wchar_t c1 = L"hi"[3]; // { dg-error "array subscript" } constexpr char16_t c2 = u"hi"[3]; // { dg-error "array subscript" } constexpr char32_t c3 = U"hi"[3]; // { dg-error "array subscript" } +constexpr char c4 = u8"hi"[3]; // { dg-error "array subscript" } diff --git a/gcc/testsuite/g++.dg/cpp0x/udlit-implicit-conv-neg-char8_t.C b/gcc/testsuite/g++.dg/cpp0x/udlit-implicit-conv-neg-char8_t.C new file mode 100644 index 00000000000..b917b5f6b90 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/udlit-implicit-conv-neg-char8_t.C @@ -0,0 +1,81 @@ +// { dg-options "-std=c++17 -fchar8_t" } + +#include <cstdint> + +int operator"" _bar (long double); + +double operator"" _foo (long long unsigned); + +int i = 12_bar; // { dg-error "unable to find numeric literal operator|with|argument" } + +double d = 1.2_foo; // { dg-error "unable to find numeric literal operator|with|argument" } + +int operator"" _char(char); + +int operator"" _char8_t(char8_t); + +int operator"" _wchar_t(wchar_t); + +int operator"" _char16_t(char16_t); + +int operator"" _char32_t(char32_t); + +int cwcx = 'c'_wchar_t; // { dg-error "unable to find character literal operator|with|argument" } +int cc8 = 'c'_char8_t; // { dg-error "unable to find character literal operator|with|argument" } +int cc16 = 'c'_char16_t; // { dg-error "unable to find character literal operator|with|argument" } +int cc32 = 'c'_char32_t; // { dg-error "unable to find character literal operator|with|argument" } + +int wccx = L'c'_char; // { dg-error "unable to find character literal operator|with|argument" } +int wcc8 = L'c'_char8_t; // { dg-error "unable to find character literal operator|with|argument" } +int wcc16 = L'c'_char16_t; // { dg-error "unable to find character literal operator|with|argument" } +int wcc32 = L'c'_char32_t; // { dg-error "unable to find character literal operator|with|argument" } + +int c8c = u8'c'_char; // { dg-error "unable to find character literal operator|with|argument" } +int c8wc = u8'c'_wchar_t; // { dg-error "unable to find character literal operator|with|argument" } +int c8c16 = u8'c'_char16_t; // { dg-error "unable to find character literal operator|with|argument" } +int c8c32 = u8'c'_char32_t; // { dg-error "unable to find character literal operator|with|argument" } + +int c16c = u'c'_char; // { dg-error "unable to find character literal operator|with|argument" } +int c16c8 = u'c'_char8_t; // { dg-error "unable to find character literal operator|with|argument" } +int c16wc = u'c'_wchar_t; // { dg-error "unable to find character literal operator|with|argument" } +int c16c32 = u'c'_char32_t; // { dg-error "unable to find character literal operator|with|argument" } + +int c32c = U'c'_char; // { dg-error "unable to find character literal operator|with|argument" } +int c32c8 = U'c'_char8_t; // { dg-error "unable to find character literal operator|with|argument" } +int c32wc = U'c'_wchar_t; // { dg-error "unable to find character literal operator|with|argument" } +int c32c16 = U'c'_char16_t; // { dg-error "unable to find character literal operator|with|argument" } + +int operator"" _char_str(const char*, std::size_t); + +int operator"" _wchar_t_str(const wchar_t*, std::size_t); + +int operator"" _char8_t_str(const char8_t*, std::size_t); + +int operator"" _char16_t_str(const char16_t*, std::size_t); + +int operator"" _char32_t_str(const char32_t*, std::size_t); + +int strwstr = "str"_wchar_t_str; // { dg-error "unable to find string literal operator|with|arguments" } +int strstr8 = "str"_char8_t_str; // { dg-error "unable to find string literal operator|with|arguments" } +int strstr16 = "str"_char16_t_str; // { dg-error "unable to find string literal operator|with|arguments" } +int strstr32 = "str"_char32_t_str; // { dg-error "unable to find string literal operator|with|arguments" } + +int str8str = u8"str"_char_str; // { dg-error "unable to find string literal operator|with|arguments" } +int str8wstr = u8"str"_wchar_t_str; // { dg-error "unable to find string literal operator|with|arguments" } +int str8str16 = u8"str"_char16_t_str; // { dg-error "unable to find string literal operator|with|arguments" } +int str8str32 = u8"str"_char32_t_str; // { dg-error "unable to find string literal operator|with|arguments" } + +int wstrstr = L"str"_char_str; // { dg-error "unable to find string literal operator|with|arguments" } +int wstrstr8 = L"str"_char8_t_str; // { dg-error "unable to find string literal operator|with|arguments" } +int wstrstr16 = L"str"_char16_t_str; // { dg-error "unable to find string literal operator|with|arguments" } +int wstrstr32 = L"str"_char32_t_str; // { dg-error "unable to find string literal operator|with|arguments" } + +int str16str = u"str"_char_str; // { dg-error "unable to find string literal operator|with|arguments" } +int str16wstr = u"str"_wchar_t_str; // { dg-error "unable to find string literal operator|with|arguments" } +int str16str8 = u"str"_char8_t_str; // { dg-error "unable to find string literal operator|with|arguments" } +int str16str32 = u"str"_char32_t_str; // { dg-error "unable to find string literal operator|with|arguments" } + +int str32str = U"str"_char_str; // { dg-error "unable to find string literal operator|with|arguments" } +int str32wstr = U"str"_wchar_t_str; // { dg-error "unable to find string literal operator|with|arguments" } +int str32str8 = U"str"_char8_t_str; // { dg-error "unable to find string literal operator string operator|with|arguments" } +int str32str16 = U"str"_char16_t_str; // { dg-error "unable to find string literal operator string operator|with|arguments" } diff --git a/gcc/testsuite/g++.dg/cpp0x/udlit-resolve-char8_t.C b/gcc/testsuite/g++.dg/cpp0x/udlit-resolve-char8_t.C new file mode 100644 index 00000000000..19cbd519a86 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/udlit-resolve-char8_t.C @@ -0,0 +1,38 @@ +// { dg-options "-std=c++17 -fchar8_t" } + +#include <cstdint> +#include <cassert> + +int operator"" _foo(const char*) { return 0; } +int operator"" _foo(unsigned long long int) { return 1; } +int operator"" _foo(long double) { return 2; } +int operator"" _foo(char) { return 3; } +int operator"" _foo(wchar_t) { return 4; } +int operator"" _foo(char8_t) { return 5; } +int operator"" _foo(char16_t) { return 6; } +int operator"" _foo(char32_t) { return 7; } +int operator"" _foo(const char*, std::size_t) { return 8; } +int operator"" _foo(const wchar_t*, std::size_t) { return 9; } +int operator"" _foo(const char8_t*, std::size_t) { return 10; } +int operator"" _foo(const char16_t*, std::size_t) { return 11; } +int operator"" _foo(const char32_t*, std::size_t) { return 12; } +template<char...> int operator"" _foo2() { return 20; } +int operator"" _foo2(unsigned long long int) { return 21; } + +int +main() +{ + assert(123_foo == 1); + assert(0.123_foo == 2); + assert('c'_foo == 3); + assert(L'c'_foo == 4); + assert(u8'c'_foo == 5); + assert(u'c'_foo == 6); + assert(U'c'_foo == 7); + assert("abc"_foo == 8); + assert(L"abc"_foo == 9); + assert(u8"abc"_foo == 10); + assert(u"abc"_foo == 11); + assert(U"abc"_foo == 12); + assert(123_foo2 == 21); +} diff --git a/gcc/testsuite/g++.dg/cpp0x/udlit-string-length.C b/gcc/testsuite/g++.dg/cpp0x/udlit-string-length.C index acfda45d5fe..c76b0af9a28 100644 --- a/gcc/testsuite/g++.dg/cpp0x/udlit-string-length.C +++ b/gcc/testsuite/g++.dg/cpp0x/udlit-string-length.C @@ -9,6 +9,14 @@ operator"" _len(const char*, size_type len) return len; } +#if __cpp_char8_t +constexpr size_type +operator"" _len(const char8_t*, size_type len) +{ + return len; +} +#endif + constexpr size_type operator"" _len(const wchar_t*, size_type len) { diff --git a/gcc/testsuite/g++.dg/cpp0x/udlit-string-literal.C b/gcc/testsuite/g++.dg/cpp0x/udlit-string-literal.C index 734a0f38ad0..ab65dd08714 100644 --- a/gcc/testsuite/g++.dg/cpp0x/udlit-string-literal.C +++ b/gcc/testsuite/g++.dg/cpp0x/udlit-string-literal.C @@ -7,7 +7,9 @@ using namespace my_string_literals; decltype("Hello, World!"s) s; +#if !__cpp_char8_t == !__cpp_lib_char8_t decltype(u8"Hello, World!"s) s8; +#endif decltype(L"Hello, World!"s) ws; decltype(u"Hello, World!"s) s16; decltype(U"Hello, World!"s) s32; diff --git a/gcc/testsuite/g++.dg/cpp0x/udlit-string-literal.h b/gcc/testsuite/g++.dg/cpp0x/udlit-string-literal.h index e61034ec4ef..c8725fa9f46 100644 --- a/gcc/testsuite/g++.dg/cpp0x/udlit-string-literal.h +++ b/gcc/testsuite/g++.dg/cpp0x/udlit-string-literal.h @@ -8,6 +8,12 @@ inline namespace my_string_literals operator"" s(const char* str, std::size_t len) { return std::string{str, len}; } +#if __cpp_lib_char8_t + std::u8string + operator"" s(const char8_t* str, std::size_t len) + { return std::u8string{str, len}; } +#endif + std::wstring operator"" s(const wchar_t* str, std::size_t len) { return std::wstring{str, len}; } |