From 8038cd7ac34d49490f63686317efc0300ddd3e4b Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 25 Jul 2022 16:40:16 +1200 Subject: [PATCH] Fix C++20 compatibility in testcases --- Examples/test-suite/cpp11_raw_string_literals.i | 9 +++++---- Examples/test-suite/cpp11_userdefined_literals.i | 3 +++ Examples/test-suite/cpp17_u8_char_literals.i | 3 ++- Examples/test-suite/template_construct.i | 6 ++++++ Examples/test-suite/valuewrapper_opaque.i | 2 +- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Examples/test-suite/cpp11_raw_string_literals.i b/Examples/test-suite/cpp11_raw_string_literals.i index 813374928..fb861377e 100644 --- a/Examples/test-suite/cpp11_raw_string_literals.i +++ b/Examples/test-suite/cpp11_raw_string_literals.i @@ -1,7 +1,7 @@ /* This module tests whether SWIG correctly parses: - - ordinary strings (char_t) + - ordinary strings (char) - L wide strings (wchar_t) - - u8 unicode8 strings (char_t) + - u8 unicode8 strings (char / char8_t since C++20) - u unicode16 strings (char16_t) - U unicode32 strings (char32_t) @@ -49,7 +49,8 @@ struct URStruct { // New string literals wstring aa = L"Wide string"; -const char *bb = u8"UTF-8 string"; +// u8"" is const char8_t[N] in C++20; const char[N] from C++11 until then. +const char *bb = reinterpret_cast(u8"UTF-8 string"); const char16_t *cc = u"UTF-16 string"; const char32_t *dd = U"UTF-32 string"; // New char literals @@ -62,7 +63,7 @@ char32_t char32_t_char = U'b'; const char *xx = ")I'm an \"ascii\" \\ string."; const char *ee = R"XXX()I'm an "ascii" \ string.)XXX"; wstring ff = LR"XXX(I'm a "raw wide" \ string.)XXX"; -const char *gg = u8R"XXX(I'm a "raw UTF-8" \ string.)XXX"; +const char *gg = reinterpret_cast(u8R"XXX(I'm a "raw UTF-8" \ string.)XXX"); const char16_t *hh = uR"XXX(I'm a "raw UTF-16" \ string.)XXX"; const char32_t *ii = UR"XXX(I'm a "raw UTF-32" \ string.)XXX"; %} diff --git a/Examples/test-suite/cpp11_userdefined_literals.i b/Examples/test-suite/cpp11_userdefined_literals.i index 9284739cd..37dc6c5ff 100644 --- a/Examples/test-suite/cpp11_userdefined_literals.i +++ b/Examples/test-suite/cpp11_userdefined_literals.i @@ -30,6 +30,9 @@ OutputType operator "" _mySuffixFloat(long double) { return OutputType(30); } // Cooked string literals OutputType operator "" _mySuffix1(const char * string_values, size_t num_chars) { return OutputType(100); } +#ifdef __cpp_lib_char8_t // For C++20 +OutputType operator "" _mySuffix1(const char8_t * string_values, size_t num_chars) { return OutputType(100); } +#endif OutputType operator "" _mySuffix2(const wchar_t * string_values, size_t num_chars) { return OutputType(200); } OutputType operator "" _mySuffix3(const char16_t * string_values, size_t num_chars) { return OutputType(300); } OutputType operator "" _mySuffix4(const char32_t * string_values, size_t num_chars) { return OutputType(400); } diff --git a/Examples/test-suite/cpp17_u8_char_literals.i b/Examples/test-suite/cpp17_u8_char_literals.i index 1aae1b231..16f0498ec 100644 --- a/Examples/test-suite/cpp17_u8_char_literals.i +++ b/Examples/test-suite/cpp17_u8_char_literals.i @@ -8,7 +8,8 @@ #endif %} -// UTF-8 character literals will (apparently) have type char8_t in C++20. +// UTF-8 character literals are type `char` in C++17 but `char8_t` in C++20, +// but the latter can be assigned to `char`. char a = u8'a'; char u = u8'u'; char u8 = u8'8'; diff --git a/Examples/test-suite/template_construct.i b/Examples/test-suite/template_construct.i index a6e8c3c33..ac418f8e5 100644 --- a/Examples/test-suite/template_construct.i +++ b/Examples/test-suite/template_construct.i @@ -7,7 +7,13 @@ template class Foo { T y; public: +#ifdef SWIG Foo(T x) : y(x) { } +#else + // Modern compilers reject this, so feed the compiler the corrected + // version. + Foo(T x) : y(x) { } +#endif }; %} diff --git a/Examples/test-suite/valuewrapper_opaque.i b/Examples/test-suite/valuewrapper_opaque.i index bc7ba8683..962bd2f81 100644 --- a/Examples/test-suite/valuewrapper_opaque.i +++ b/Examples/test-suite/valuewrapper_opaque.i @@ -14,7 +14,7 @@ class C; %{ template class TemplateClass { public: -TemplateClass(T a) {} +TemplateClass(T a) {} }; struct B