mirror of https://github.com/swig/swig
Fix C++20 compatibility in testcases
This commit is contained in:
parent
5a4baece4f
commit
8038cd7ac3
|
@ -1,7 +1,7 @@
|
||||||
/* This module tests whether SWIG correctly parses:
|
/* This module tests whether SWIG correctly parses:
|
||||||
- ordinary strings (char_t)
|
- ordinary strings (char)
|
||||||
- L wide strings (wchar_t)
|
- 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 unicode16 strings (char16_t)
|
||||||
- U unicode32 strings (char32_t)
|
- U unicode32 strings (char32_t)
|
||||||
|
|
||||||
|
@ -49,7 +49,8 @@ struct URStruct {
|
||||||
|
|
||||||
// New string literals
|
// New string literals
|
||||||
wstring aa = L"Wide string";
|
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<const char*>(u8"UTF-8 string");
|
||||||
const char16_t *cc = u"UTF-16 string";
|
const char16_t *cc = u"UTF-16 string";
|
||||||
const char32_t *dd = U"UTF-32 string";
|
const char32_t *dd = U"UTF-32 string";
|
||||||
// New char literals
|
// New char literals
|
||||||
|
@ -62,7 +63,7 @@ char32_t char32_t_char = U'b';
|
||||||
const char *xx = ")I'm an \"ascii\" \\ string.";
|
const char *xx = ")I'm an \"ascii\" \\ string.";
|
||||||
const char *ee = R"XXX()I'm an "ascii" \ string.)XXX";
|
const char *ee = R"XXX()I'm an "ascii" \ string.)XXX";
|
||||||
wstring ff = LR"XXX(I'm a "raw wide" \ 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<const char*>(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 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";
|
const char32_t *ii = UR"XXX(I'm a "raw UTF-32" \ string.)XXX";
|
||||||
%}
|
%}
|
||||||
|
|
|
@ -30,6 +30,9 @@ OutputType operator "" _mySuffixFloat(long double) { return OutputType(30); }
|
||||||
|
|
||||||
// Cooked string literals
|
// Cooked string literals
|
||||||
OutputType operator "" _mySuffix1(const char * string_values, size_t num_chars) { return OutputType(100); }
|
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 "" _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 "" _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); }
|
OutputType operator "" _mySuffix4(const char32_t * string_values, size_t num_chars) { return OutputType(400); }
|
||||||
|
|
|
@ -8,7 +8,8 @@
|
||||||
#endif
|
#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 a = u8'a';
|
||||||
char u = u8'u';
|
char u = u8'u';
|
||||||
char u8 = u8'8';
|
char u8 = u8'8';
|
||||||
|
|
|
@ -7,7 +7,13 @@ template<class T>
|
||||||
class Foo {
|
class Foo {
|
||||||
T y;
|
T y;
|
||||||
public:
|
public:
|
||||||
|
#ifdef SWIG
|
||||||
Foo<T>(T x) : y(x) { }
|
Foo<T>(T x) : y(x) { }
|
||||||
|
#else
|
||||||
|
// Modern compilers reject this, so feed the compiler the corrected
|
||||||
|
// version.
|
||||||
|
Foo(T x) : y(x) { }
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
|
@ -14,7 +14,7 @@ class C;
|
||||||
%{
|
%{
|
||||||
template<typename T> class TemplateClass {
|
template<typename T> class TemplateClass {
|
||||||
public:
|
public:
|
||||||
TemplateClass<T>(T a) {}
|
TemplateClass(T a) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct B
|
struct B
|
||||||
|
|
Loading…
Reference in New Issue