From 35b792daed7bebaadd74c2f48a66c694fa4d70ed Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 3 May 2018 18:57:46 +0100 Subject: [PATCH] test-suite support for C++17: exception specification throw removal --- Examples/test-suite/catches.i | 20 ++----- Examples/test-suite/cplusplus_throw.i | 22 ++------ Examples/test-suite/cpp11_final_override.i | 22 ++------ Examples/test-suite/cpp11_lambda_functions.i | 36 +++++-------- Examples/test-suite/csharp_exceptions.i | 45 ++++++---------- Examples/test-suite/default_args.i | 25 ++++----- Examples/test-suite/director_exception.i | 20 +++---- Examples/test-suite/exception_order.i | 22 ++------ Examples/test-suite/exception_partial_info.i | 22 ++------ Examples/test-suite/extern_throws.i | 22 ++------ Examples/test-suite/intermediary_classname.i | 22 +++----- .../java_director_exception_feature.i | 16 +++--- .../java_director_exception_feature_nspace.i | 14 ++--- Examples/test-suite/java_throws.i | 23 +++----- Examples/test-suite/li_std_except.i | 52 +++++++------------ Examples/test-suite/li_std_except_as_class.i | 22 ++------ Examples/test-suite/li_std_string.i | 32 +++--------- Examples/test-suite/li_std_wstring.i | 23 +++----- Examples/test-suite/primitive_types.i | 36 ++++++------- Examples/test-suite/python_builtin.i | 22 ++------ Examples/test-suite/threads_exception.i | 31 ++++------- Examples/test-suite/throw_exception.i | 40 +++++--------- Examples/test-suite/using_pointers.i | 20 ++----- 23 files changed, 190 insertions(+), 419 deletions(-) diff --git a/Examples/test-suite/catches.i b/Examples/test-suite/catches.i index 8456cc00b..d3402a303 100644 --- a/Examples/test-suite/catches.i +++ b/Examples/test-suite/catches.i @@ -1,13 +1,9 @@ %module catches +// throw is invalid in C++17 and later, only SWIG to use it +#define TESTCASE_THROW(TYPES...) throw(TYPES) %{ -#if defined(_MSC_VER) - #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11 -#endif +#define TESTCASE_THROW(TYPES...) %} %include // for throws(...) typemap @@ -27,7 +23,7 @@ void test_catches(int i) { throw ThreeException(); } } -void test_exception_specification(int i) throw(int, const char *, const ThreeException&) { +void test_exception_specification(int i) TESTCASE_THROW(int, const char *, const ThreeException&) { test_catches(i); } void test_catches_all(int i) { @@ -35,11 +31,3 @@ void test_catches_all(int i) { } %} -%{ -#if defined(_MSC_VER) - #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic pop -#endif -%} diff --git a/Examples/test-suite/cplusplus_throw.i b/Examples/test-suite/cplusplus_throw.i index 112f9f3b5..4fba97f34 100644 --- a/Examples/test-suite/cplusplus_throw.i +++ b/Examples/test-suite/cplusplus_throw.i @@ -5,14 +5,10 @@ %module cplusplus_throw +// throw is invalid in C++17 and later, only SWIG to use it +#define TESTCASE_THROW(TYPES...) throw(TYPES) %{ -#if defined(_MSC_VER) - #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11 -#endif +#define TESTCASE_THROW(TYPES...) %} %nodefaultctor; @@ -24,17 +20,9 @@ class Foo { }; class Bar { public: void baz() const { }; - void foo() throw (Foo) { }; - void bazfoo() const throw (int) { }; + void foo() TESTCASE_THROW(Foo) { }; + void bazfoo() const TESTCASE_THROW(int) { }; }; %} -%{ -#if defined(_MSC_VER) - #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic pop -#endif -%} diff --git a/Examples/test-suite/cpp11_final_override.i b/Examples/test-suite/cpp11_final_override.i index 3a0d963f0..1fa306cd5 100644 --- a/Examples/test-suite/cpp11_final_override.i +++ b/Examples/test-suite/cpp11_final_override.i @@ -6,14 +6,10 @@ %warnfilter(SWIGWARN_PARSE_KEYWORD) final; // 'final' is a java keyword, renaming to '_final' %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) %{ -#if defined(_MSC_VER) - #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11 -#endif +#define TESTCASE_THROW(TYPES...) %} %inline %{ @@ -43,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() throw(int) override final {} - virtual void finaloverride6() const throw(int) override final {} + virtual void finaloverride5() TESTCASE_THROW(int) override final {} + virtual void finaloverride6() const TESTCASE_THROW(int) override final {} virtual ~Derived() override final {} }; void Derived::override2() const noexcept {} @@ -142,11 +138,3 @@ void DerivedNoVirtualStruct::ef() {} DerivedNoVirtualStruct::~DerivedNoVirtualStruct() {} %} -%{ -#if defined(_MSC_VER) - #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic pop -#endif -%} diff --git a/Examples/test-suite/cpp11_lambda_functions.i b/Examples/test-suite/cpp11_lambda_functions.i index a12870ccd..c50839913 100644 --- a/Examples/test-suite/cpp11_lambda_functions.i +++ b/Examples/test-suite/cpp11_lambda_functions.i @@ -26,14 +26,10 @@ %warnfilter(SWIGWARN_CPP11_LAMBDA) Space1::lambda19; %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) %{ -#if defined(_MSC_VER) - #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11 -#endif +#define TESTCASE_THROW(TYPES...) %} %inline %{ @@ -61,22 +57,22 @@ 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) throw() -> int { return x+y; }; -auto lambda9 = [] (int x, int y) mutable throw() -> int { return x+y; }; -auto lambda10 = [] (int x, int y) throw(int) { return x+y; }; -auto lambda11 = [] (int x, int y) mutable throw(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 lambda12 = [] (int a, int b) { return a + b; }(1, 2); auto lambda13 = [] (int a, int b) mutable { return a + b; }(1, 2); -auto lambda14 = [] () throw () {}; -auto lambda15 = [] () mutable throw () {}; +auto lambda14 = [] () TESTCASE_THROW() {}; +auto lambda15 = [] () mutable TESTCASE_THROW() {}; auto lambda16 = [] { return thing; }; auto lambda17 = [] { return thing; }(); -constexpr auto lambda18 = [] (int x, int y) mutable throw(int) { return x+y; }; +constexpr auto lambda18 = [] (int x, int y) mutable TESTCASE_THROW(int) { return x+y; }; namespace Space1 { - constexpr auto lambda19 = [] (int x, int y) mutable throw(int) { return x+y; }; + constexpr auto lambda19 = [] (int x, int y) mutable TESTCASE_THROW(int) { return x+y; }; namespace Space2 { - constexpr auto lambda20 = [] (int x, int y) mutable throw(int) { return x+y; }; + constexpr auto lambda20 = [] (int x, int y) mutable TESTCASE_THROW(int) { return x+y; }; } } @@ -115,11 +111,3 @@ int lambda102 = [] (int a, int b) mutable { return a + b; }(1, 2); void lambda_init(int = ([=]{ return 0; })()); %} -%{ -#if defined(_MSC_VER) - #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic pop -#endif -%} diff --git a/Examples/test-suite/csharp_exceptions.i b/Examples/test-suite/csharp_exceptions.i index 53e51eb09..639117b16 100644 --- a/Examples/test-suite/csharp_exceptions.i +++ b/Examples/test-suite/csharp_exceptions.i @@ -1,5 +1,11 @@ %module csharp_exceptions +// throw is invalid in C++17 and later, only SWIG to use it +#define TESTCASE_THROW(TYPES...) throw(TYPES) +%{ +#define TESTCASE_THROW(TYPES...) +%} + %include %inline %{ @@ -36,25 +42,16 @@ } %inline %{ - -#if defined(_MSC_VER) - #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11 -#endif - // %exception tests void ThrowByValue() { throw Ex("ThrowByValue"); } void ThrowByReference() { throw Ex("ThrowByReference"); } // %csnothrowexception void NoThrowException() { throw Ex("NoThrowException"); } // exception specifications -void ExceptionSpecificationValue() throw(Ex) { throw Ex("ExceptionSpecificationValue"); } -void ExceptionSpecificationReference() throw(Ex&) { throw Ex("ExceptionSpecificationReference"); } -void ExceptionSpecificationString() throw(const char *) { throw "ExceptionSpecificationString"; } -void ExceptionSpecificationInteger() throw(int) { throw 20; } +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; } %} // test exceptions in the default typemaps @@ -68,15 +65,15 @@ void NullValue(Ex e) {} // enums %inline %{ enum TestEnum {TestEnumItem}; -void ExceptionSpecificationEnumValue() throw(TestEnum) { throw TestEnumItem; } -void ExceptionSpecificationEnumReference() throw(TestEnum&) { throw TestEnumItem; } +void ExceptionSpecificationEnumValue() TESTCASE_THROW(TestEnum) { throw TestEnumItem; } +void ExceptionSpecificationEnumReference() TESTCASE_THROW(TestEnum&) { throw TestEnumItem; } %} // std::string %include %inline %{ -void ExceptionSpecificationStdStringValue() throw(std::string) { throw std::string("ExceptionSpecificationStdStringValue"); } -void ExceptionSpecificationStdStringReference() throw(const std::string&) { throw std::string("ExceptionSpecificationStdStringReference"); } +void ExceptionSpecificationStdStringValue() TESTCASE_THROW(std::string) { throw std::string("ExceptionSpecificationStdStringValue"); } +void ExceptionSpecificationStdStringReference() TESTCASE_THROW(const std::string&) { throw std::string("ExceptionSpecificationStdStringReference"); } void NullStdStringValue(std::string s) {} void NullStdStringReference(std::string &s) {} %} @@ -108,12 +105,8 @@ void MemoryLeakCheck() { %inline %{ struct constructor { constructor(std::string s) {} - constructor() throw(int) { throw 10; } + constructor() TESTCASE_THROW(int) { throw 10; } }; - -#if defined(_MSC_VER) - #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif %} // test exception pending in the csout typemaps @@ -244,11 +237,3 @@ struct ThrowsClass { void InnerExceptionTest() { throw Ex("My InnerException message"); } %} -%{ -#if defined(_MSC_VER) - #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic pop -#endif -%} diff --git a/Examples/test-suite/default_args.i b/Examples/test-suite/default_args.i index 2dc2bccc1..e6fe7a050 100644 --- a/Examples/test-suite/default_args.i +++ b/Examples/test-suite/default_args.i @@ -4,13 +4,14 @@ %{ #if defined(_MSC_VER) - #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) #pragma warning(disable: 4146) // unary minus operator applied to unsigned type, result still unsigned #endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11 -#endif +%} + +// throw is invalid in C++17 and later, only SWIG to use it +#define TESTCASE_THROW(TYPES...) throw(TYPES) +%{ +#define TESTCASE_THROW(TYPES...) %} %include @@ -203,18 +204,18 @@ // Default parameters with exception specifications %inline %{ -void exceptionspec(int a = -1) throw (int, const char*) { +void exceptionspec(int a = -1) TESTCASE_THROW(int, const char*) { if (a == -1) throw "ciao"; else throw a; } struct Except { - Except(bool throwException, int a = -1) throw (int) { + Except(bool throwException, int a = -1) TESTCASE_THROW(int) { if (throwException) throw a; } - void exspec(int a = 0) throw (int, const char*) { + void exspec(int a = 0) TESTCASE_THROW(int, const char*) { ::exceptionspec(a); } }; @@ -326,11 +327,3 @@ struct CDA { }; %} -%{ -#if defined(_MSC_VER) - #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic pop -#endif -%} diff --git a/Examples/test-suite/director_exception.i b/Examples/test-suite/director_exception.i index e25bfdcca..78bd715cd 100644 --- a/Examples/test-suite/director_exception.i +++ b/Examples/test-suite/director_exception.i @@ -3,18 +3,20 @@ %warnfilter(SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) return_const_char_star; %{ - +// throw is deprecated in C++11 and invalid in C++17 and later +#if defined(__cplusplus) && __cplusplus >= 201103L +#define throw(TYPES...) +#else +#define throw(TYPES...) throw(TYPES) #if defined(_MSC_VER) #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) #endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11 #endif +%} +%{ #include - // define dummy director exception classes to prevent spurious errors // in target languages that do not support directors. @@ -137,16 +139,16 @@ Foo *launder(Foo *f) { class Base { public: - virtual ~Base() throw () {} + virtual ~Base() throw() {} }; class Bar : public Base { public: - virtual std::string ping() throw (Exception1, Exception2&) { return "Bar::ping()"; } - virtual std::string pong() throw (Unknown1, int, Unknown2&) { return "Bar::pong();" + ping(); } - virtual std::string pang() throw () { return "Bar::pang()"; } + virtual std::string ping() throw(Exception1, Exception2&) { return "Bar::ping()"; } + virtual std::string pong() throw(Unknown1, int, Unknown2&) { return "Bar::pong();" + ping(); } + virtual std::string pang() throw() { return "Bar::pang()"; } }; // Class to allow regression testing SWIG/PHP not checking if an exception diff --git a/Examples/test-suite/exception_order.i b/Examples/test-suite/exception_order.i index 194394332..87e87f896 100644 --- a/Examples/test-suite/exception_order.i +++ b/Examples/test-suite/exception_order.i @@ -12,14 +12,10 @@ %include "exception.i" +// throw is invalid in C++17 and later, only SWIG to use it +#define TESTCASE_THROW(TYPES...) throw(TYPES) %{ -#if defined(_MSC_VER) - #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11 -#endif +#define TESTCASE_THROW(TYPES...) %} /* @@ -103,13 +99,13 @@ int efoovar; /* caught by the user's throw definition */ - int foo() throw(E1) + int foo() TESTCASE_THROW(E1) { throw E1(); return 0; } - int bar() throw(E2) + int bar() TESTCASE_THROW(E2) { throw E2(); return 0; @@ -151,11 +147,3 @@ bool is_python_builtin() { return false; } %template(ET_i) ET; %template(ET_d) ET; -%{ -#if defined(_MSC_VER) - #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic pop -#endif -%} diff --git a/Examples/test-suite/exception_partial_info.i b/Examples/test-suite/exception_partial_info.i index e39ccb063..5d2ebfaf6 100644 --- a/Examples/test-suite/exception_partial_info.i +++ b/Examples/test-suite/exception_partial_info.i @@ -2,14 +2,10 @@ // 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) %{ -#if defined(_MSC_VER) - #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11 -#endif +#define TESTCASE_THROW(TYPES...) %} %{ @@ -40,8 +36,8 @@ class ex2 : public myException class Impl { public: - void f1() throw (myException) { ex1 e; throw e; } - void f2() throw (myException) { ex2 e; throw e; } + void f1() TESTCASE_THROW(myException) { ex1 e; throw e; } + void f2() TESTCASE_THROW(myException) { ex2 e; throw e; } }; %} @@ -53,11 +49,3 @@ class Impl #warning "UTL needs fixing for partial exception information" #endif -%{ -#if defined(_MSC_VER) - #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic pop -#endif -%} diff --git a/Examples/test-suite/extern_throws.i b/Examples/test-suite/extern_throws.i index 81eeb64c2..082a346a2 100644 --- a/Examples/test-suite/extern_throws.i +++ b/Examples/test-suite/extern_throws.i @@ -1,30 +1,18 @@ %module extern_throws +// throw is invalid in C++17 and later, only SWIG to use it +#define TESTCASE_THROW(TYPES...) throw(TYPES) %{ -#if defined(_MSC_VER) - #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11 -#endif +#define TESTCASE_THROW(TYPES...) %} %inline %{ #include -extern int get() throw(std::exception); +extern int get() TESTCASE_THROW(std::exception); %} %{ -int get() throw(std::exception) { return 0; } +int get() TESTCASE_THROW(std::exception) { return 0; } %} -%{ -#if defined(_MSC_VER) - #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic pop -#endif -%} diff --git a/Examples/test-suite/intermediary_classname.i b/Examples/test-suite/intermediary_classname.i index 6e544f298..e0a4c97c1 100644 --- a/Examples/test-suite/intermediary_classname.i +++ b/Examples/test-suite/intermediary_classname.i @@ -4,6 +4,12 @@ %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_THROW(TYPES...) +%} + // change the access to the intermediary class for testing purposes %pragma(java) jniclassclassmodifiers="public class"; %pragma(csharp) imclassclassmodifiers="public class"; @@ -41,14 +47,6 @@ template class vector { void testconst(const T x) { } }; -#if defined(_MSC_VER) - #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11 -#endif - class Base { public: Base() : mVectInt(0) {} @@ -69,14 +67,8 @@ public: virtual Base& m1(Base &b) { return b; } virtual Base* m2(Base *b) { return b; } // virtual Base m3(Base b) { return b; } - void throwspec() throw (int, Base) {} + void throwspec() TESTCASE_THROW(int, Base) {} }; -#if defined(_MSC_VER) - #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic pop -#endif %} %template(maxint) maximum; diff --git a/Examples/test-suite/java_director_exception_feature.i b/Examples/test-suite/java_director_exception_feature.i index b5b9c3938..d9187a65d 100644 --- a/Examples/test-suite/java_director_exception_feature.i +++ b/Examples/test-suite/java_director_exception_feature.i @@ -4,14 +4,10 @@ %warnfilter(SWIGWARN_TYPEMAP_DIRECTORTHROWS_UNDEF) MyNS::Foo::directorthrows_warning; +// throw is invalid in C++17 and later, only SWIG to use it +#define TESTCASE_THROW(TYPES...) throw(TYPES) %{ -#if defined(_MSC_VER) - #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11 -#endif +#define TESTCASE_THROW(TYPES...) %} %include @@ -184,10 +180,10 @@ public: virtual ~Foo() {} // ping java implementation throws a java Exception1 or an Exception2 if excp is 1 or 2. // pong java implementation throws Exception1,Exception2,Unexpected,NullPointerException for 1,2,3,4 - virtual std::string ping(int excp) throw(int,MyNS::Exception2) = 0; + virtual std::string ping(int excp) TESTCASE_THROW(int,MyNS::Exception2) = 0; virtual std::string pong(int excp) /* throws MyNS::Exception1 MyNS::Exception2 MyNS::Unexpected) */ = 0; virtual std::string genericpong(int excp) /* unspecified throws - exception is always DirectorException in C++, translated back to whatever thrown in java */ = 0; - virtual std::string directorthrows_warning(int excp) throw(double) { return std::string(); } + virtual std::string directorthrows_warning(int excp) TESTCASE_THROW(double) { return std::string(); } }; // Make a bar from a foo, so a call to Java Bar @@ -196,7 +192,7 @@ public: class Bar { public: Bar(Foo* d) { delegate=d; } - virtual std::string ping(int excp) throw(int,MyNS::Exception2) + virtual std::string ping(int excp) TESTCASE_THROW(int,MyNS::Exception2) { return delegate->ping(excp); } diff --git a/Examples/test-suite/java_director_exception_feature_nspace.i b/Examples/test-suite/java_director_exception_feature_nspace.i index 9f542fd37..3f843147e 100644 --- a/Examples/test-suite/java_director_exception_feature_nspace.i +++ b/Examples/test-suite/java_director_exception_feature_nspace.i @@ -11,14 +11,10 @@ #define PACKAGESLASH "java_director_exception_feature_nspacePackage/" %} +// throw is invalid in C++17 and later, only SWIG to use it +#define TESTCASE_THROW(TYPES...) throw(TYPES) %{ -#if defined(_MSC_VER) - #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11 -#endif +#define TESTCASE_THROW(TYPES...) %} %include @@ -191,7 +187,7 @@ public: virtual ~Foo() {} // ping java implementation throws a java Exception1 or an Exception2 if excp is 1 or 2. // pong java implementation throws Exception1,Exception2,Unexpected,NullPointerException for 1,2,3,4 - virtual std::string ping(int excp) throw(int,MyNS::Exception2) = 0; + virtual std::string ping(int excp) TESTCASE_THROW(int,MyNS::Exception2) = 0; virtual std::string pong(int excp) /* throws MyNS::Exception1 MyNS::Exception2 MyNS::Unexpected) */ = 0; virtual std::string genericpong(int excp) /* unspecified throws - exception is always DirectorException in C++, translated back to whatever thrown in java */ = 0; }; @@ -202,7 +198,7 @@ public: class Bar { public: Bar(Foo* d) { delegate=d; } - virtual std::string ping(int excp) throw(int,MyNS::Exception2) + virtual std::string ping(int excp) TESTCASE_THROW(int,MyNS::Exception2) { return delegate->ping(excp); } diff --git a/Examples/test-suite/java_throws.i b/Examples/test-suite/java_throws.i index bb5c6e48f..2e4d5c2ab 100644 --- a/Examples/test-suite/java_throws.i +++ b/Examples/test-suite/java_throws.i @@ -2,6 +2,12 @@ %module java_throws +// throw is invalid in C++17 and later, only SWIG to use it +#define TESTCASE_THROW(TYPES...) throw(TYPES) +%{ +#define TESTCASE_THROW(TYPES...) +%} + // Exceptions are chosen at random but are ones which have to have a try catch block to compile %typemap(in, throws=" ClassNotFoundException") int num { $1 = (int)$input; @@ -39,22 +45,7 @@ short full_of_exceptions(int num) { return $null; } %inline %{ -#if defined(_MSC_VER) - #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11 -#endif - -bool throw_spec_function(int value) throw (int) { throw (int)0; } - -#if defined(_MSC_VER) - #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic pop -#endif +bool throw_spec_function(int value) TESTCASE_THROW(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 8c96a11f8..fe621e3b4 100644 --- a/Examples/test-suite/li_std_except.i +++ b/Examples/test-suite/li_std_except.i @@ -2,17 +2,12 @@ %include +// throw is invalid in C++17 and later, only SWIG to use it +#define TESTCASE_THROW(TYPES...) throw(TYPES) %{ -#if defined(_MSC_VER) - #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11 -#endif +#define TESTCASE_THROW(TYPES...) %} - %inline %{ struct E1 : public std::exception { @@ -23,32 +18,23 @@ }; struct Test { - int foo1() throw(std::bad_exception) { return 0; } - int foo2() throw(std::logic_error) { return 0; } - int foo3() throw(E1) { return 0; } - int foo4() throw(E2) { return 0; } + 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; } // all the STL exceptions... - void throw_bad_cast() throw(std::bad_cast) { throw std::bad_cast(); } - void throw_bad_exception() throw(std::bad_exception) { throw std::bad_exception(); } - void throw_domain_error() throw(std::domain_error) { throw std::domain_error("oops"); } - void throw_exception() throw(std::exception) { throw std::exception(); } - void throw_invalid_argument() throw(std::invalid_argument) { throw std::invalid_argument("oops"); } - void throw_length_error() throw(std::length_error) { throw std::length_error("oops"); } - void throw_logic_error() throw(std::logic_error) { throw std::logic_error("oops"); } - void throw_out_of_range() throw(std::out_of_range) { throw std::out_of_range("oops"); } - void throw_overflow_error() throw(std::overflow_error) { throw std::overflow_error("oops"); } - void throw_range_error() throw(std::range_error) { throw std::range_error("oops"); } - void throw_runtime_error() throw(std::runtime_error) { throw std::runtime_error("oops"); } - void throw_underflow_error() throw(std::underflow_error) { throw std::underflow_error("oops"); } + 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"); } }; %} - -%{ -#if defined(_MSC_VER) - #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic pop -#endif -%} diff --git a/Examples/test-suite/li_std_except_as_class.i b/Examples/test-suite/li_std_except_as_class.i index 1b5dd6082..5055d013c 100644 --- a/Examples/test-suite/li_std_except_as_class.i +++ b/Examples/test-suite/li_std_except_as_class.i @@ -5,27 +5,23 @@ * if there were also functions throwing 'std::logic_error' and * '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) %{ -#if defined(_MSC_VER) - #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11 -#endif +#define TESTCASE_THROW(TYPES...) %} %{ #include #include -void test_domain_error() throw(std::domain_error) +void test_domain_error() TESTCASE_THROW(std::domain_error, int) { throw std::domain_error("std::domain_error"); } %} %include #define SWIG_STD_EXCEPTIONS_AS_CLASSES %include -void test_domain_error() throw(std::domain_error) +void test_domain_error() TESTCASE_THROW(std::domain_error, int) { throw std::domain_error("std::domain_error"); } %inline %{ @@ -36,11 +32,3 @@ bool is_python_builtin() { return false; } #endif %} -%{ -#if defined(_MSC_VER) - #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic pop -#endif -%} diff --git a/Examples/test-suite/li_std_string.i b/Examples/test-suite/li_std_string.i index 15042c464..280fe6f5a 100644 --- a/Examples/test-suite/li_std_string.i +++ b/Examples/test-suite/li_std_string.i @@ -6,17 +6,12 @@ %apply std::string& INOUT { std::string &inout } #endif +// throw is invalid in C++17 and later, only SWIG to use it +#define TESTCASE_THROW(TYPES...) throw(TYPES) %{ -#if defined(_MSC_VER) - #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11 -#endif +#define TESTCASE_THROW(TYPES...) %} - %inline %{ std::string test_value(std::string x) { @@ -59,28 +54,23 @@ void test_reference_inout(std::string &inout) { inout += inout; } -void test_throw() throw(std::string){ +void test_throw() TESTCASE_THROW(std::string){ static std::string x = "test_throw message"; throw x; } -void test_const_reference_throw() throw(const std::string &){ +void test_const_reference_throw() TESTCASE_THROW(const std::string &){ static std::string x = "test_const_reference_throw message"; throw x; } -void test_pointer_throw() throw(std::string *) { +void test_pointer_throw() TESTCASE_THROW(std::string *) { throw new std::string("foo"); } -void test_const_pointer_throw() throw(const std::string *) { +void test_const_pointer_throw() TESTCASE_THROW(const std::string *) { throw new std::string("foo"); } - -#if defined(_MSC_VER) - #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif - %} /* Old way, now std::string is a %naturalvar by default @@ -162,11 +152,3 @@ public: } %} -%{ -#if defined(_MSC_VER) - #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic pop -#endif -%} diff --git a/Examples/test-suite/li_std_wstring.i b/Examples/test-suite/li_std_wstring.i index fe1166be3..1bdeb9bf8 100644 --- a/Examples/test-suite/li_std_wstring.i +++ b/Examples/test-suite/li_std_wstring.i @@ -3,6 +3,12 @@ %include +// throw is invalid in C++17 and later, only SWIG to use it +#define TESTCASE_THROW(TYPES...) throw(TYPES) +%{ +#define TESTCASE_THROW(TYPES...) +%} + %inline %{ struct A : std::wstring @@ -82,27 +88,12 @@ bool test_equal_abc(const std::wstring &s) { return L"abc" == s; } -#if defined(_MSC_VER) - #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11 -#endif - -void test_throw() throw(std::wstring){ +void test_throw() TESTCASE_THROW(std::wstring){ static std::wstring x = L"x"; throw x; } -#if defined(_MSC_VER) - #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic pop -#endif - #ifdef SWIGPYTHON_BUILTIN bool is_python_builtin() { return true; } #else diff --git a/Examples/test-suite/primitive_types.i b/Examples/test-suite/primitive_types.i index c68b1fc8f..637934377 100644 --- a/Examples/test-suite/primitive_types.i +++ b/Examples/test-suite/primitive_types.i @@ -7,16 +7,6 @@ %rename(TestDir) TestDirector; #endif -%{ -#if defined(_MSC_VER) - #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11 -#endif -%} - // Ruby constant names #pragma SWIG nowarn=SWIGWARN_RUBY_WRONG_NAME @@ -263,14 +253,17 @@ macro(Param, pfx, paramc) macro(size_t, pfx, sizet) %enddef +%define catches_decl(type, pfx, name) + %catches(type) pfx##_##name(type x); +%enddef /* function passing by value */ %define val_decl(type, pfx, name) - type pfx##_##name(type x) throw (type) { return x; } + type pfx##_##name(type x) { return x; } %enddef /* function passing by ref */ %define ref_decl(type, pfx, name) - const type& pfx##_##name(const type& x) throw (type) { return x; } + const type& pfx##_##name(const type& x) { return x; } %enddef /* C++ constant declaration */ @@ -305,6 +298,11 @@ macro(size_t, pfx, sizet) %test_prim_types(sct_decl, sct) +%test_prim_types(catches_decl, val) +%test_prim_types(catches_decl, ref) +%test_prim_types(catches_decl, cct) +%test_prim_types(catches_decl, var) + %inline { %test_prim_types(val_decl, val) %test_prim_types(ref_decl, ref) @@ -456,12 +454,12 @@ macro(size_t, pfx, sizet) var_decl(namet, var, namet) - const char* val_namet(namet x) throw(namet) + const char* val_namet(namet x) { return x; } - const char* val_cnamet(const namet x) throw(namet) + const char* val_cnamet(const namet x) { return x; } @@ -469,7 +467,7 @@ macro(size_t, pfx, sizet) #if 0 /* I have no idea how to define a typemap for const namet&, where namet is a char[ANY] array */ - const namet& ref_namet(const namet& x) throw(namet) + const namet& ref_namet(const namet& x) { return x; } @@ -513,12 +511,12 @@ macro(size_t, pfx, sizet) var_namet[0]='h'; } - virtual const char* vval_namet(namet x) throw(namet) + virtual const char* vval_namet(namet x) { return x; } - virtual const char* vval_cnamet(const namet x) throw(namet) + virtual const char* vval_cnamet(const namet x) { return x; } @@ -526,7 +524,7 @@ macro(size_t, pfx, sizet) #if 0 /* I have no idea how to define a typemap for const namet&, where namet is a char[ANY] array */ - virtual const namet& vref_namet(const namet& x) throw(namet) + virtual const namet& vref_namet(const namet& x) { return x; } @@ -563,7 +561,7 @@ macro(size_t, pfx, sizet) %test_prim_types_ovr(ovr_decl, ovr) - virtual Test* vtest(Test* t) const throw (Test) + virtual Test* vtest(Test* t) const { return t; } diff --git a/Examples/test-suite/python_builtin.i b/Examples/test-suite/python_builtin.i index 21cbda3e9..c8a755868 100644 --- a/Examples/test-suite/python_builtin.i +++ b/Examples/test-suite/python_builtin.i @@ -2,14 +2,10 @@ %module python_builtin +// throw is invalid in C++17 and later, only SWIG to use it +#define TESTCASE_THROW(TYPES...) throw(TYPES) %{ -#if defined(_MSC_VER) - #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11 -#endif +#define TESTCASE_THROW(TYPES...) %} %inline %{ @@ -196,13 +192,13 @@ void Dealloc2Destroyer(PyObject *v) { return size; } - int __getitem__(Py_ssize_t n) throw (std::out_of_range) { + int __getitem__(Py_ssize_t n) TESTCASE_THROW(std::out_of_range) { if (n >= (int)size) throw std::out_of_range("Index too large"); return numbers[n]; } - SimpleArray __getitem__(PySliceObject *slice) throw (std::out_of_range, std::invalid_argument) { + SimpleArray __getitem__(PySliceObject *slice) TESTCASE_THROW(std::out_of_range, std::invalid_argument) { if (!PySlice_Check(slice)) throw std::invalid_argument("Slice object expected"); Py_ssize_t i, j, step; @@ -228,11 +224,3 @@ void Dealloc2Destroyer(PyObject *v) { }; %} -%{ -#if defined(_MSC_VER) - #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic pop -#endif -%} diff --git a/Examples/test-suite/threads_exception.i b/Examples/test-suite/threads_exception.i index a9865da3c..6d62a8b95 100644 --- a/Examples/test-suite/threads_exception.i +++ b/Examples/test-suite/threads_exception.i @@ -4,6 +4,12 @@ %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_THROW(TYPES...) +%} + %{ struct A {}; %} @@ -11,14 +17,6 @@ struct A {}; %inline %{ #include -#if defined(_MSC_VER) - #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11 -#endif - class Exc { public: Exc(int c, const char *m) { @@ -32,24 +30,24 @@ public: class Test { public: - int simple() throw(int) { + int simple() TESTCASE_THROW(int) { throw(37); return 1; } - int message() throw(const char *) { + int message() TESTCASE_THROW(const char *) { throw("I died."); return 1; } - int hosed() throw(Exc) { + int hosed() TESTCASE_THROW(Exc) { throw(Exc(42,"Hosed")); return 1; } - int unknown() throw(A*) { + int unknown() TESTCASE_THROW(A*) { static A a; throw &a; return 1; } - int multi(int x) throw(int, const char *, Exc) { + int multi(int x) TESTCASE_THROW(int, const char *, Exc) { if (x == 1) throw(37); if (x == 2) throw("Bleah!"); if (x == 3) throw(Exc(42,"No-go-diggy-die")); @@ -62,11 +60,4 @@ bool is_python_builtin() { return true; } #else bool is_python_builtin() { return false; } #endif - -#if defined(_MSC_VER) - #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic pop -#endif %} diff --git a/Examples/test-suite/throw_exception.i b/Examples/test-suite/throw_exception.i index 777e55b9e..916208cce 100644 --- a/Examples/test-suite/throw_exception.i +++ b/Examples/test-suite/throw_exception.i @@ -1,13 +1,9 @@ %module throw_exception +// throw is invalid in C++17 and later, only SWIG to use it +#define TESTCASE_THROW(TYPES...) throw(TYPES) %{ -#if defined(_MSC_VER) - #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11 -#endif +#define TESTCASE_THROW(TYPES...) %} %warnfilter(SWIGWARN_RUBY_WRONG_NAME) Namespace::enum1; @@ -34,45 +30,45 @@ namespace Namespace { } class Foo { public: - void test_int() throw(int) { + void test_int() TESTCASE_THROW(int) { throw 37; } - void test_msg() throw(const char *) { + void test_msg() TESTCASE_THROW(const char *) { throw "Dead"; } - void test_cls() throw(CError) { + void test_cls() TESTCASE_THROW(CError) { throw CError(); } - void test_cls_ptr() throw(CError *) { + void test_cls_ptr() TESTCASE_THROW(CError *) { static CError StaticError; throw &StaticError; } - void test_cls_ref() throw(CError &) { + void test_cls_ref() TESTCASE_THROW(CError &) { static CError StaticError; throw StaticError; } - void test_cls_td() throw(Namespace::ErrorTypedef) { + void test_cls_td() TESTCASE_THROW(Namespace::ErrorTypedef) { throw CError(); } - void test_cls_ptr_td() throw(Namespace::ErrorPtr) { + void test_cls_ptr_td() TESTCASE_THROW(Namespace::ErrorPtr) { static CError StaticError; throw &StaticError; } - void test_cls_ref_td() throw(Namespace::ErrorRef) { + void test_cls_ref_td() TESTCASE_THROW(Namespace::ErrorRef) { static CError StaticError; throw StaticError; } - void test_array() throw(Namespace::IntArray) { + void test_array() TESTCASE_THROW(Namespace::IntArray) { static Namespace::IntArray array; for (int i=0; i<10; i++) { array[i] = i; } throw array; } - void test_enum() throw(Namespace::EnumTest) { + void test_enum() TESTCASE_THROW(Namespace::EnumTest) { throw Namespace::enum2; } - void test_multi(int x) throw(int, const char *, CError) { + void test_multi(int x) TESTCASE_THROW(int, const char *, CError) { if (x == 1) throw 37; if (x == 2) throw "Dead"; if (x == 3) throw CError(); @@ -81,11 +77,3 @@ public: %} -%{ -#if defined(_MSC_VER) - #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic pop -#endif -%} diff --git a/Examples/test-suite/using_pointers.i b/Examples/test-suite/using_pointers.i index 569acce25..8c7ff1702 100644 --- a/Examples/test-suite/using_pointers.i +++ b/Examples/test-suite/using_pointers.i @@ -4,14 +4,10 @@ %csmethodmodifiers x "public new" #endif +// throw is invalid in C++17 and later, only SWIG to use it +#define TESTCASE_THROW(TYPES...) throw(TYPES) %{ -#if defined(_MSC_VER) - #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11 -#endif +#define TESTCASE_THROW(TYPES...) %} %inline %{ @@ -20,7 +16,7 @@ int x; virtual ~Foo() { } virtual Foo* blah() { return this; } - virtual Foo* exception_spec(int what_to_throw) throw (int, const char *) { + virtual Foo* exception_spec(int what_to_throw) TESTCASE_THROW(int, const char *) { int num = 10; const char *str = "exception message"; if (what_to_throw == 1) throw num; @@ -38,11 +34,3 @@ %} -%{ -#if defined(_MSC_VER) - #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic pop -#endif -%}