From 196a965067ff677ad109ab84320e1a7aa69c77d1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 5 May 2018 11:45:44 +0100 Subject: [PATCH] test-suite fixes for compilers that don't support vararg macros Split TESTCASE_THROW into multiple macros taking different number of arguments. Fixes Visual Studio compiler errors. --- Examples/test-suite/catches.i | 6 ++-- Examples/test-suite/cplusplus_throw.i | 8 ++--- Examples/test-suite/cpp11_final_override.i | 8 ++--- Examples/test-suite/cpp11_lambda_functions.i | 24 +++++++------ Examples/test-suite/csharp_exceptions.i | 22 ++++++------ Examples/test-suite/default_args.i | 12 ++++--- Examples/test-suite/exception_order.i | 14 ++++---- Examples/test-suite/exception_partial_info.i | 8 ++--- Examples/test-suite/extern_throws.i | 8 ++--- Examples/test-suite/intermediary_classname.i | 6 ++-- Examples/test-suite/java_throws.i | 6 ++-- Examples/test-suite/li_std_except.i | 36 ++++++++++---------- Examples/test-suite/li_std_except_as_class.i | 8 ++--- Examples/test-suite/li_std_string.i | 12 +++---- Examples/test-suite/li_std_wstring.i | 6 ++-- Examples/test-suite/python_builtin.i | 10 +++--- Examples/test-suite/threads_exception.i | 16 +++++---- Examples/test-suite/throw_exception.i | 28 ++++++++------- Examples/test-suite/using_pointers.i | 6 ++-- 19 files changed, 127 insertions(+), 117 deletions(-) diff --git a/Examples/test-suite/catches.i b/Examples/test-suite/catches.i index d3402a303..89cf43f8d 100644 --- a/Examples/test-suite/catches.i +++ b/Examples/test-suite/catches.i @@ -1,9 +1,9 @@ %module catches // throw is invalid in C++17 and later, only SWIG to use it -#define TESTCASE_THROW(TYPES...) throw(TYPES) +#define TESTCASE_THROW3(T1, T2, T3) throw(T1, T2, T3) %{ -#define TESTCASE_THROW(TYPES...) +#define TESTCASE_THROW3(T1, T2, T3) %} %include // for throws(...) typemap @@ -23,7 +23,7 @@ void test_catches(int i) { throw ThreeException(); } } -void test_exception_specification(int i) TESTCASE_THROW(int, const char *, const ThreeException&) { +void test_exception_specification(int i) TESTCASE_THROW3(int, const char *, const ThreeException&) { test_catches(i); } void test_catches_all(int i) { diff --git a/Examples/test-suite/cplusplus_throw.i b/Examples/test-suite/cplusplus_throw.i index 4fba97f34..72ae62938 100644 --- a/Examples/test-suite/cplusplus_throw.i +++ b/Examples/test-suite/cplusplus_throw.i @@ -6,9 +6,9 @@ %module cplusplus_throw // throw is invalid in C++17 and later, only SWIG to use it -#define TESTCASE_THROW(TYPES...) throw(TYPES) +#define TESTCASE_THROW1(T1) throw(T1) %{ -#define TESTCASE_THROW(TYPES...) +#define TESTCASE_THROW1(T1) %} %nodefaultctor; @@ -20,8 +20,8 @@ class Foo { }; class Bar { public: void baz() const { }; - void foo() TESTCASE_THROW(Foo) { }; - void bazfoo() const TESTCASE_THROW(int) { }; + void foo() TESTCASE_THROW1(Foo) { }; + void bazfoo() const TESTCASE_THROW1(int) { }; }; %} diff --git a/Examples/test-suite/cpp11_final_override.i b/Examples/test-suite/cpp11_final_override.i index 1fa306cd5..8d275b322 100644 --- a/Examples/test-suite/cpp11_final_override.i +++ b/Examples/test-suite/cpp11_final_override.i @@ -7,9 +7,9 @@ %warnfilter(SWIGWARN_PARSE_KEYWORD) override; // 'override' is a C# keyword, renaming to '_override' // throw is invalid in C++17 and later, only SWIG to use it -#define TESTCASE_THROW(TYPES...) throw(TYPES) +#define TESTCASE_THROW1(T1) throw(T1) %{ -#define TESTCASE_THROW(TYPES...) +#define TESTCASE_THROW1(T1) %} %inline %{ @@ -39,8 +39,8 @@ struct Derived /*final*/ : Base { virtual void finaloverride2() override final {} virtual void finaloverride3() noexcept override final {} virtual void finaloverride4() const noexcept override final {} - virtual void finaloverride5() TESTCASE_THROW(int) override final {} - virtual void finaloverride6() const TESTCASE_THROW(int) override final {} + virtual void finaloverride5() TESTCASE_THROW1(int) override final {} + virtual void finaloverride6() const TESTCASE_THROW1(int) override final {} virtual ~Derived() override final {} }; void Derived::override2() const noexcept {} diff --git a/Examples/test-suite/cpp11_lambda_functions.i b/Examples/test-suite/cpp11_lambda_functions.i index eb368a626..fc02aadb2 100644 --- a/Examples/test-suite/cpp11_lambda_functions.i +++ b/Examples/test-suite/cpp11_lambda_functions.i @@ -27,9 +27,11 @@ %warnfilter(SWIGWARN_CPP11_LAMBDA) Space1::Space2::lambda20; // throw is invalid in C++17 and later, only SWIG to use it -#define TESTCASE_THROW(TYPES...) throw(TYPES) +#define TESTCASE_THROW0() throw() +#define TESTCASE_THROW1(T1) throw(T1) %{ -#define TESTCASE_THROW(TYPES...) +#define TESTCASE_THROW0() +#define TESTCASE_THROW1(T1) %} %inline %{ @@ -57,14 +59,14 @@ void fn() { } auto lambda6 = [] (int a, int b) mutable { return a + b; }; auto lambda7 = [] (int x, int y) -> int { return x+y; }; -auto lambda8 = [] (int x, int y) TESTCASE_THROW() -> int { return x+y; }; -auto lambda9 = [] (int x, int y) mutable TESTCASE_THROW() -> int { return x+y; }; -auto lambda10 = [] (int x, int y) TESTCASE_THROW(int) { return x+y; }; -auto lambda11 = [] (int x, int y) mutable TESTCASE_THROW(int) { return x+y; }; +auto lambda8 = [] (int x, int y) TESTCASE_THROW0() -> int { return x+y; }; +auto lambda9 = [] (int x, int y) mutable TESTCASE_THROW0() -> int { return x+y; }; +auto lambda10 = [] (int x, int y) TESTCASE_THROW1(int) { return x+y; }; +auto lambda11 = [] (int x, int y) mutable TESTCASE_THROW1(int) { return x+y; }; auto lambda12 = [] (int a, int b) { return a + b; }(1, 2); auto lambda13 = [] (int a, int b) mutable { return a + b; }(1, 2); -auto lambda14 = [] () TESTCASE_THROW() {}; -auto lambda15 = [] () mutable TESTCASE_THROW() {}; +auto lambda14 = [] () TESTCASE_THROW0() {}; +auto lambda15 = [] () mutable TESTCASE_THROW0() {}; auto lambda16 = [] { return thing; }; auto lambda17 = [] { return thing; }(); #if defined(SWIG) || (defined(__cplusplus) && __cplusplus >= 201703L) @@ -72,12 +74,12 @@ auto lambda17 = [] { return thing; }(); #else #define CONSTEXPR #endif -CONSTEXPR auto lambda18 = [] (int x, int y) mutable TESTCASE_THROW(int) { return x+y; }; +CONSTEXPR auto lambda18 = [] (int x, int y) mutable TESTCASE_THROW1(int) { return x+y; }; namespace Space1 { - CONSTEXPR auto lambda19 = [] (int x, int y) mutable TESTCASE_THROW(int) { return x+y; }; + CONSTEXPR auto lambda19 = [] (int x, int y) mutable TESTCASE_THROW1(int) { return x+y; }; namespace Space2 { - CONSTEXPR auto lambda20 = [] (int x, int y) mutable TESTCASE_THROW(int) { return x+y; }; + CONSTEXPR auto lambda20 = [] (int x, int y) mutable TESTCASE_THROW1(int) { return x+y; }; } } diff --git a/Examples/test-suite/csharp_exceptions.i b/Examples/test-suite/csharp_exceptions.i index 639117b16..71581480e 100644 --- a/Examples/test-suite/csharp_exceptions.i +++ b/Examples/test-suite/csharp_exceptions.i @@ -1,9 +1,9 @@ %module csharp_exceptions // throw is invalid in C++17 and later, only SWIG to use it -#define TESTCASE_THROW(TYPES...) throw(TYPES) +#define TESTCASE_THROW1(T1) throw(T1) %{ -#define TESTCASE_THROW(TYPES...) +#define TESTCASE_THROW1(T1) %} %include @@ -48,10 +48,10 @@ void ThrowByReference() { throw Ex("ThrowByRefer // %csnothrowexception void NoThrowException() { throw Ex("NoThrowException"); } // exception specifications -void ExceptionSpecificationValue() TESTCASE_THROW(Ex) { throw Ex("ExceptionSpecificationValue"); } -void ExceptionSpecificationReference() TESTCASE_THROW(Ex&) { throw Ex("ExceptionSpecificationReference"); } -void ExceptionSpecificationString() TESTCASE_THROW(const char *) { throw "ExceptionSpecificationString"; } -void ExceptionSpecificationInteger() TESTCASE_THROW(int) { throw 20; } +void ExceptionSpecificationValue() TESTCASE_THROW1(Ex) { throw Ex("ExceptionSpecificationValue"); } +void ExceptionSpecificationReference() TESTCASE_THROW1(Ex&) { throw Ex("ExceptionSpecificationReference"); } +void ExceptionSpecificationString() TESTCASE_THROW1(const char *) { throw "ExceptionSpecificationString"; } +void ExceptionSpecificationInteger() TESTCASE_THROW1(int) { throw 20; } %} // test exceptions in the default typemaps @@ -65,15 +65,15 @@ void NullValue(Ex e) {} // enums %inline %{ enum TestEnum {TestEnumItem}; -void ExceptionSpecificationEnumValue() TESTCASE_THROW(TestEnum) { throw TestEnumItem; } -void ExceptionSpecificationEnumReference() TESTCASE_THROW(TestEnum&) { throw TestEnumItem; } +void ExceptionSpecificationEnumValue() TESTCASE_THROW1(TestEnum) { throw TestEnumItem; } +void ExceptionSpecificationEnumReference() TESTCASE_THROW1(TestEnum&) { throw TestEnumItem; } %} // std::string %include %inline %{ -void ExceptionSpecificationStdStringValue() TESTCASE_THROW(std::string) { throw std::string("ExceptionSpecificationStdStringValue"); } -void ExceptionSpecificationStdStringReference() TESTCASE_THROW(const std::string&) { throw std::string("ExceptionSpecificationStdStringReference"); } +void ExceptionSpecificationStdStringValue() TESTCASE_THROW1(std::string) { throw std::string("ExceptionSpecificationStdStringValue"); } +void ExceptionSpecificationStdStringReference() TESTCASE_THROW1(const std::string&) { throw std::string("ExceptionSpecificationStdStringReference"); } void NullStdStringValue(std::string s) {} void NullStdStringReference(std::string &s) {} %} @@ -105,7 +105,7 @@ void MemoryLeakCheck() { %inline %{ struct constructor { constructor(std::string s) {} - constructor() TESTCASE_THROW(int) { throw 10; } + constructor() TESTCASE_THROW1(int) { throw 10; } }; %} diff --git a/Examples/test-suite/default_args.i b/Examples/test-suite/default_args.i index e6fe7a050..450a8c7bf 100644 --- a/Examples/test-suite/default_args.i +++ b/Examples/test-suite/default_args.i @@ -9,9 +9,11 @@ %} // throw is invalid in C++17 and later, only SWIG to use it -#define TESTCASE_THROW(TYPES...) throw(TYPES) +#define TESTCASE_THROW1(T1) throw(T1) +#define TESTCASE_THROW2(T1, T2) throw(T1, T2) %{ -#define TESTCASE_THROW(TYPES...) +#define TESTCASE_THROW1(T1) +#define TESTCASE_THROW2(T1, T2) %} %include @@ -204,18 +206,18 @@ // Default parameters with exception specifications %inline %{ -void exceptionspec(int a = -1) TESTCASE_THROW(int, const char*) { +void exceptionspec(int a = -1) TESTCASE_THROW2(int, const char*) { if (a == -1) throw "ciao"; else throw a; } struct Except { - Except(bool throwException, int a = -1) TESTCASE_THROW(int) { + Except(bool throwException, int a = -1) TESTCASE_THROW1(int) { if (throwException) throw a; } - void exspec(int a = 0) TESTCASE_THROW(int, const char*) { + void exspec(int a = 0) TESTCASE_THROW2(int, const char*) { ::exceptionspec(a); } }; diff --git a/Examples/test-suite/exception_order.i b/Examples/test-suite/exception_order.i index 87e87f896..e2411634b 100644 --- a/Examples/test-suite/exception_order.i +++ b/Examples/test-suite/exception_order.i @@ -13,9 +13,9 @@ %include "exception.i" // throw is invalid in C++17 and later, only SWIG to use it -#define TESTCASE_THROW(TYPES...) throw(TYPES) +#define TESTCASE_THROW1(T1) throw(T1) %{ -#define TESTCASE_THROW(TYPES...) +#define TESTCASE_THROW1(T1) %} /* @@ -99,16 +99,16 @@ int efoovar; /* caught by the user's throw definition */ - int foo() TESTCASE_THROW(E1) + int foo() TESTCASE_THROW1(E1) { throw E1(); - return 0; + return 0; } - - int bar() TESTCASE_THROW(E2) + + int bar() TESTCASE_THROW1(E2) { throw E2(); - return 0; + return 0; } /* caught by %postexception */ diff --git a/Examples/test-suite/exception_partial_info.i b/Examples/test-suite/exception_partial_info.i index 5d2ebfaf6..3ac465cf6 100644 --- a/Examples/test-suite/exception_partial_info.i +++ b/Examples/test-suite/exception_partial_info.i @@ -3,9 +3,9 @@ // This produced compilable code for Tcl, Python in 1.3.27, fails in 1.3.29 // throw is invalid in C++17 and later, only SWIG to use it -#define TESTCASE_THROW(TYPES...) throw(TYPES) +#define TESTCASE_THROW1(T1) throw(T1) %{ -#define TESTCASE_THROW(TYPES...) +#define TESTCASE_THROW1(T1) %} %{ @@ -36,8 +36,8 @@ class ex2 : public myException class Impl { public: - void f1() TESTCASE_THROW(myException) { ex1 e; throw e; } - void f2() TESTCASE_THROW(myException) { ex2 e; throw e; } + void f1() TESTCASE_THROW1(myException) { ex1 e; throw e; } + void f2() TESTCASE_THROW1(myException) { ex2 e; throw e; } }; %} diff --git a/Examples/test-suite/extern_throws.i b/Examples/test-suite/extern_throws.i index 082a346a2..92ece4158 100644 --- a/Examples/test-suite/extern_throws.i +++ b/Examples/test-suite/extern_throws.i @@ -1,18 +1,18 @@ %module extern_throws // throw is invalid in C++17 and later, only SWIG to use it -#define TESTCASE_THROW(TYPES...) throw(TYPES) +#define TESTCASE_THROW1(T1) throw(T1) %{ -#define TESTCASE_THROW(TYPES...) +#define TESTCASE_THROW1(T1) %} %inline %{ #include -extern int get() TESTCASE_THROW(std::exception); +extern int get() TESTCASE_THROW1(std::exception); %} %{ -int get() TESTCASE_THROW(std::exception) { return 0; } +int get() TESTCASE_THROW1(std::exception) { return 0; } %} diff --git a/Examples/test-suite/intermediary_classname.i b/Examples/test-suite/intermediary_classname.i index e0a4c97c1..585967ad4 100644 --- a/Examples/test-suite/intermediary_classname.i +++ b/Examples/test-suite/intermediary_classname.i @@ -5,9 +5,9 @@ %warnfilter(SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR); // throw is invalid in C++17 and later, only SWIG to use it -#define TESTCASE_THROW(TYPES...) throw(TYPES) +#define TESTCASE_THROW2(T1, T2) throw(T1, T2) %{ -#define TESTCASE_THROW(TYPES...) +#define TESTCASE_THROW2(T1, T2) %} // change the access to the intermediary class for testing purposes @@ -67,7 +67,7 @@ public: virtual Base& m1(Base &b) { return b; } virtual Base* m2(Base *b) { return b; } // virtual Base m3(Base b) { return b; } - void throwspec() TESTCASE_THROW(int, Base) {} + void throwspec() TESTCASE_THROW2(int, Base) {} }; %} diff --git a/Examples/test-suite/java_throws.i b/Examples/test-suite/java_throws.i index 2e4d5c2ab..5dc353b6d 100644 --- a/Examples/test-suite/java_throws.i +++ b/Examples/test-suite/java_throws.i @@ -3,9 +3,9 @@ %module java_throws // throw is invalid in C++17 and later, only SWIG to use it -#define TESTCASE_THROW(TYPES...) throw(TYPES) +#define TESTCASE_THROW1(T1) throw(T1) %{ -#define TESTCASE_THROW(TYPES...) +#define TESTCASE_THROW1(T1) %} // Exceptions are chosen at random but are ones which have to have a try catch block to compile @@ -45,7 +45,7 @@ short full_of_exceptions(int num) { return $null; } %inline %{ -bool throw_spec_function(int value) TESTCASE_THROW(int) { throw (int)0; } +bool throw_spec_function(int value) TESTCASE_THROW1(int) { throw (int)0; } %} %catches(int) catches_function(int value); diff --git a/Examples/test-suite/li_std_except.i b/Examples/test-suite/li_std_except.i index fe621e3b4..60bce999d 100644 --- a/Examples/test-suite/li_std_except.i +++ b/Examples/test-suite/li_std_except.i @@ -3,9 +3,9 @@ %include // throw is invalid in C++17 and later, only SWIG to use it -#define TESTCASE_THROW(TYPES...) throw(TYPES) +#define TESTCASE_THROW1(T1) throw(T1) %{ -#define TESTCASE_THROW(TYPES...) +#define TESTCASE_THROW1(T1) %} %inline %{ @@ -18,23 +18,23 @@ }; struct Test { - int foo1() TESTCASE_THROW(std::bad_exception) { return 0; } - int foo2() TESTCASE_THROW(std::logic_error) { return 0; } - int foo3() TESTCASE_THROW(E1) { return 0; } - int foo4() TESTCASE_THROW(E2) { return 0; } + int foo1() TESTCASE_THROW1(std::bad_exception) { return 0; } + int foo2() TESTCASE_THROW1(std::logic_error) { return 0; } + int foo3() TESTCASE_THROW1(E1) { return 0; } + int foo4() TESTCASE_THROW1(E2) { return 0; } // all the STL exceptions... - void throw_bad_cast() TESTCASE_THROW(std::bad_cast) { throw std::bad_cast(); } - void throw_bad_exception() TESTCASE_THROW(std::bad_exception) { throw std::bad_exception(); } - void throw_domain_error() TESTCASE_THROW(std::domain_error) { throw std::domain_error("oops"); } - void throw_exception() TESTCASE_THROW(std::exception) { throw std::exception(); } - void throw_invalid_argument() TESTCASE_THROW(std::invalid_argument) { throw std::invalid_argument("oops"); } - void throw_length_error() TESTCASE_THROW(std::length_error) { throw std::length_error("oops"); } - void throw_logic_error() TESTCASE_THROW(std::logic_error) { throw std::logic_error("oops"); } - void throw_out_of_range() TESTCASE_THROW(std::out_of_range) { throw std::out_of_range("oops"); } - void throw_overflow_error() TESTCASE_THROW(std::overflow_error) { throw std::overflow_error("oops"); } - void throw_range_error() TESTCASE_THROW(std::range_error) { throw std::range_error("oops"); } - void throw_runtime_error() TESTCASE_THROW(std::runtime_error) { throw std::runtime_error("oops"); } - void throw_underflow_error() TESTCASE_THROW(std::underflow_error) { throw std::underflow_error("oops"); } + void throw_bad_cast() TESTCASE_THROW1(std::bad_cast) { throw std::bad_cast(); } + void throw_bad_exception() TESTCASE_THROW1(std::bad_exception) { throw std::bad_exception(); } + void throw_domain_error() TESTCASE_THROW1(std::domain_error) { throw std::domain_error("oops"); } + void throw_exception() TESTCASE_THROW1(std::exception) { throw std::exception(); } + void throw_invalid_argument() TESTCASE_THROW1(std::invalid_argument) { throw std::invalid_argument("oops"); } + void throw_length_error() TESTCASE_THROW1(std::length_error) { throw std::length_error("oops"); } + void throw_logic_error() TESTCASE_THROW1(std::logic_error) { throw std::logic_error("oops"); } + void throw_out_of_range() TESTCASE_THROW1(std::out_of_range) { throw std::out_of_range("oops"); } + void throw_overflow_error() TESTCASE_THROW1(std::overflow_error) { throw std::overflow_error("oops"); } + void throw_range_error() TESTCASE_THROW1(std::range_error) { throw std::range_error("oops"); } + void throw_runtime_error() TESTCASE_THROW1(std::runtime_error) { throw std::runtime_error("oops"); } + void throw_underflow_error() TESTCASE_THROW1(std::underflow_error) { throw std::underflow_error("oops"); } }; %} diff --git a/Examples/test-suite/li_std_except_as_class.i b/Examples/test-suite/li_std_except_as_class.i index 5055d013c..3d9706c80 100644 --- a/Examples/test-suite/li_std_except_as_class.i +++ b/Examples/test-suite/li_std_except_as_class.i @@ -6,22 +6,22 @@ * 'std::exception' then the bug would not be fully replicated */ // throw is invalid in C++17 and later, only SWIG to use it -#define TESTCASE_THROW(TYPES...) throw(TYPES) +#define TESTCASE_THROW2(T1, T2) throw(T1, T2) %{ -#define TESTCASE_THROW(TYPES...) +#define TESTCASE_THROW2(T1, T2) %} %{ #include #include -void test_domain_error() TESTCASE_THROW(std::domain_error, int) +void test_domain_error() TESTCASE_THROW2(std::domain_error, int) { throw std::domain_error("std::domain_error"); } %} %include #define SWIG_STD_EXCEPTIONS_AS_CLASSES %include -void test_domain_error() TESTCASE_THROW(std::domain_error, int) +void test_domain_error() TESTCASE_THROW2(std::domain_error, int) { throw std::domain_error("std::domain_error"); } %inline %{ diff --git a/Examples/test-suite/li_std_string.i b/Examples/test-suite/li_std_string.i index 280fe6f5a..822368491 100644 --- a/Examples/test-suite/li_std_string.i +++ b/Examples/test-suite/li_std_string.i @@ -7,9 +7,9 @@ #endif // throw is invalid in C++17 and later, only SWIG to use it -#define TESTCASE_THROW(TYPES...) throw(TYPES) +#define TESTCASE_THROW1(T1) throw(T1) %{ -#define TESTCASE_THROW(TYPES...) +#define TESTCASE_THROW1(T1) %} %inline %{ @@ -54,21 +54,21 @@ void test_reference_inout(std::string &inout) { inout += inout; } -void test_throw() TESTCASE_THROW(std::string){ +void test_throw() TESTCASE_THROW1(std::string){ static std::string x = "test_throw message"; throw x; } -void test_const_reference_throw() TESTCASE_THROW(const std::string &){ +void test_const_reference_throw() TESTCASE_THROW1(const std::string &){ static std::string x = "test_const_reference_throw message"; throw x; } -void test_pointer_throw() TESTCASE_THROW(std::string *) { +void test_pointer_throw() TESTCASE_THROW1(std::string *) { throw new std::string("foo"); } -void test_const_pointer_throw() TESTCASE_THROW(const std::string *) { +void test_const_pointer_throw() TESTCASE_THROW1(const std::string *) { throw new std::string("foo"); } %} diff --git a/Examples/test-suite/li_std_wstring.i b/Examples/test-suite/li_std_wstring.i index 1bdeb9bf8..6c0929ae5 100644 --- a/Examples/test-suite/li_std_wstring.i +++ b/Examples/test-suite/li_std_wstring.i @@ -4,9 +4,9 @@ // throw is invalid in C++17 and later, only SWIG to use it -#define TESTCASE_THROW(TYPES...) throw(TYPES) +#define TESTCASE_THROW1(T1) throw(T1) %{ -#define TESTCASE_THROW(TYPES...) +#define TESTCASE_THROW1(T1) %} %inline %{ @@ -88,7 +88,7 @@ bool test_equal_abc(const std::wstring &s) { return L"abc" == s; } -void test_throw() TESTCASE_THROW(std::wstring){ +void test_throw() TESTCASE_THROW1(std::wstring){ static std::wstring x = L"x"; throw x; diff --git a/Examples/test-suite/python_builtin.i b/Examples/test-suite/python_builtin.i index c8a755868..c48867853 100644 --- a/Examples/test-suite/python_builtin.i +++ b/Examples/test-suite/python_builtin.i @@ -3,9 +3,11 @@ %module python_builtin // throw is invalid in C++17 and later, only SWIG to use it -#define TESTCASE_THROW(TYPES...) throw(TYPES) +#define TESTCASE_THROW1(T1) throw(T1) +#define TESTCASE_THROW2(T1, T2) throw(T1, T2) %{ -#define TESTCASE_THROW(TYPES...) +#define TESTCASE_THROW1(T1) +#define TESTCASE_THROW2(T1, T2) %} %inline %{ @@ -192,13 +194,13 @@ void Dealloc2Destroyer(PyObject *v) { return size; } - int __getitem__(Py_ssize_t n) TESTCASE_THROW(std::out_of_range) { + int __getitem__(Py_ssize_t n) TESTCASE_THROW1(std::out_of_range) { if (n >= (int)size) throw std::out_of_range("Index too large"); return numbers[n]; } - SimpleArray __getitem__(PySliceObject *slice) TESTCASE_THROW(std::out_of_range, std::invalid_argument) { + SimpleArray __getitem__(PySliceObject *slice) TESTCASE_THROW2(std::out_of_range, std::invalid_argument) { if (!PySlice_Check(slice)) throw std::invalid_argument("Slice object expected"); Py_ssize_t i, j, step; diff --git a/Examples/test-suite/threads_exception.i b/Examples/test-suite/threads_exception.i index 6d62a8b95..4708633db 100644 --- a/Examples/test-suite/threads_exception.i +++ b/Examples/test-suite/threads_exception.i @@ -5,9 +5,11 @@ %module(threads="1") threads_exception // throw is invalid in C++17 and later, only SWIG to use it -#define TESTCASE_THROW(TYPES...) throw(TYPES) +#define TESTCASE_THROW1(T1) throw(T1) +#define TESTCASE_THROW3(T1, T2, T3) throw(T1, T2, T3) %{ -#define TESTCASE_THROW(TYPES...) +#define TESTCASE_THROW1(T1) +#define TESTCASE_THROW3(T1, T2, T3) %} %{ @@ -30,24 +32,24 @@ public: class Test { public: - int simple() TESTCASE_THROW(int) { + int simple() TESTCASE_THROW1(int) { throw(37); return 1; } - int message() TESTCASE_THROW(const char *) { + int message() TESTCASE_THROW1(const char *) { throw("I died."); return 1; } - int hosed() TESTCASE_THROW(Exc) { + int hosed() TESTCASE_THROW1(Exc) { throw(Exc(42,"Hosed")); return 1; } - int unknown() TESTCASE_THROW(A*) { + int unknown() TESTCASE_THROW1(A*) { static A a; throw &a; return 1; } - int multi(int x) TESTCASE_THROW(int, const char *, Exc) { + int multi(int x) TESTCASE_THROW3(int, const char *, Exc) { if (x == 1) throw(37); if (x == 2) throw("Bleah!"); if (x == 3) throw(Exc(42,"No-go-diggy-die")); diff --git a/Examples/test-suite/throw_exception.i b/Examples/test-suite/throw_exception.i index 916208cce..ed9288290 100644 --- a/Examples/test-suite/throw_exception.i +++ b/Examples/test-suite/throw_exception.i @@ -1,9 +1,11 @@ %module throw_exception // throw is invalid in C++17 and later, only SWIG to use it -#define TESTCASE_THROW(TYPES...) throw(TYPES) +#define TESTCASE_THROW1(T1) throw(T1) +#define TESTCASE_THROW3(T1, T2, T3) throw(T1, T2, T3) %{ -#define TESTCASE_THROW(TYPES...) +#define TESTCASE_THROW1(T1) +#define TESTCASE_THROW3(T1, T2, T3) %} %warnfilter(SWIGWARN_RUBY_WRONG_NAME) Namespace::enum1; @@ -30,45 +32,45 @@ namespace Namespace { } class Foo { public: - void test_int() TESTCASE_THROW(int) { + void test_int() TESTCASE_THROW1(int) { throw 37; } - void test_msg() TESTCASE_THROW(const char *) { + void test_msg() TESTCASE_THROW1(const char *) { throw "Dead"; } - void test_cls() TESTCASE_THROW(CError) { + void test_cls() TESTCASE_THROW1(CError) { throw CError(); } - void test_cls_ptr() TESTCASE_THROW(CError *) { + void test_cls_ptr() TESTCASE_THROW1(CError *) { static CError StaticError; throw &StaticError; } - void test_cls_ref() TESTCASE_THROW(CError &) { + void test_cls_ref() TESTCASE_THROW1(CError &) { static CError StaticError; throw StaticError; } - void test_cls_td() TESTCASE_THROW(Namespace::ErrorTypedef) { + void test_cls_td() TESTCASE_THROW1(Namespace::ErrorTypedef) { throw CError(); } - void test_cls_ptr_td() TESTCASE_THROW(Namespace::ErrorPtr) { + void test_cls_ptr_td() TESTCASE_THROW1(Namespace::ErrorPtr) { static CError StaticError; throw &StaticError; } - void test_cls_ref_td() TESTCASE_THROW(Namespace::ErrorRef) { + void test_cls_ref_td() TESTCASE_THROW1(Namespace::ErrorRef) { static CError StaticError; throw StaticError; } - void test_array() TESTCASE_THROW(Namespace::IntArray) { + void test_array() TESTCASE_THROW1(Namespace::IntArray) { static Namespace::IntArray array; for (int i=0; i<10; i++) { array[i] = i; } throw array; } - void test_enum() TESTCASE_THROW(Namespace::EnumTest) { + void test_enum() TESTCASE_THROW1(Namespace::EnumTest) { throw Namespace::enum2; } - void test_multi(int x) TESTCASE_THROW(int, const char *, CError) { + void test_multi(int x) TESTCASE_THROW3(int, const char *, CError) { if (x == 1) throw 37; if (x == 2) throw "Dead"; if (x == 3) throw CError(); diff --git a/Examples/test-suite/using_pointers.i b/Examples/test-suite/using_pointers.i index 8c7ff1702..1a3824afa 100644 --- a/Examples/test-suite/using_pointers.i +++ b/Examples/test-suite/using_pointers.i @@ -5,9 +5,9 @@ #endif // throw is invalid in C++17 and later, only SWIG to use it -#define TESTCASE_THROW(TYPES...) throw(TYPES) +#define TESTCASE_THROW2(T1, T2) throw(T1, T2) %{ -#define TESTCASE_THROW(TYPES...) +#define TESTCASE_THROW2(T1, T2) %} %inline %{ @@ -16,7 +16,7 @@ int x; virtual ~Foo() { } virtual Foo* blah() { return this; } - virtual Foo* exception_spec(int what_to_throw) TESTCASE_THROW(int, const char *) { + virtual Foo* exception_spec(int what_to_throw) TESTCASE_THROW2(int, const char *) { int num = 10; const char *str = "exception message"; if (what_to_throw == 1) throw num;