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.
This commit is contained in:
William S Fulton 2018-05-05 11:45:44 +01:00
parent 1c46662c39
commit 196a965067
19 changed files with 127 additions and 117 deletions

View File

@ -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 <exception.i> // 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) {

View File

@ -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) { };
};
%}

View File

@ -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 {}

View File

@ -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; };
}
}

View File

@ -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 <exception.i>
@ -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 <std_string.i>
%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; }
};
%}

View File

@ -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 <std_string.i>
@ -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);
}
};

View File

@ -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,13 +99,13 @@
int efoovar;
/* caught by the user's throw definition */
int foo() TESTCASE_THROW(E1)
int foo() TESTCASE_THROW1(E1)
{
throw E1();
return 0;
}
int bar() TESTCASE_THROW(E2)
int bar() TESTCASE_THROW1(E2)
{
throw E2();
return 0;

View File

@ -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; }
};
%}

View File

@ -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 <exception>
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; }
%}

View File

@ -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) {}
};
%}

View File

@ -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);

View File

@ -3,9 +3,9 @@
%include <std_except.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)
%}
%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"); }
};
%}

View File

@ -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 <exception>
#include <stdexcept>
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 <std_string.i>
#define SWIG_STD_EXCEPTIONS_AS_CLASSES
%include <std_except.i>
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 %{

View File

@ -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");
}
%}

View File

@ -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;

View File

@ -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;

View File

@ -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"));

View File

@ -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();

View File

@ -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;