From 63f7315c8ac504b5909b58101e06305aeeecafba Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 3 May 2018 19:10:50 +0100 Subject: [PATCH] test-suite support for C++17 (Java): exception specification throw removal --- .../java_director_exception_feature.i | 24 ++++++++++++------- .../java_director_exception_feature_nspace.i | 22 ++++++++++------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/Examples/test-suite/java_director_exception_feature.i b/Examples/test-suite/java_director_exception_feature.i index d9187a65d..e4a06185e 100644 --- a/Examples/test-suite/java_director_exception_feature.i +++ b/Examples/test-suite/java_director_exception_feature.i @@ -4,12 +4,6 @@ %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) -%{ -#define TESTCASE_THROW(TYPES...) -%} - %include // DEFINE exceptions in header section using std::runtime_error @@ -171,6 +165,18 @@ namespace MyNS { %catches(MyNS::Exception1,MyNS::Exception2,MyNS::Unexpected) MyNS::Foo::pong; %catches(MyNS::Exception1,MyNS::Exception2,MyNS::Unexpected) MyNS::Bar::pong; +%{ +// 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 +#endif +%} + %inline %{ namespace MyNS { @@ -180,10 +186,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) TESTCASE_THROW(int,MyNS::Exception2) = 0; + virtual std::string ping(int excp) 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) TESTCASE_THROW(double) { return std::string(); } + virtual std::string directorthrows_warning(int excp) throw(double) { return std::string(); } }; // Make a bar from a foo, so a call to Java Bar @@ -192,7 +198,7 @@ public: class Bar { public: Bar(Foo* d) { delegate=d; } - virtual std::string ping(int excp) TESTCASE_THROW(int,MyNS::Exception2) + virtual std::string ping(int excp) 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 3f843147e..a5f6a5315 100644 --- a/Examples/test-suite/java_director_exception_feature_nspace.i +++ b/Examples/test-suite/java_director_exception_feature_nspace.i @@ -11,12 +11,6 @@ #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) -%{ -#define TESTCASE_THROW(TYPES...) -%} - %include // DEFINE exceptions in header section using std::runtime_error @@ -178,6 +172,18 @@ namespace MyNS { %catches(MyNS::Exception1,MyNS::Exception2,MyNS::Unexpected) MyNS::Foo::pong; %catches(MyNS::Exception1,MyNS::Exception2,MyNS::Unexpected) MyNS::Bar::pong; +%{ +// 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 +#endif +%} + %inline %{ namespace MyNS { @@ -187,7 +193,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) TESTCASE_THROW(int,MyNS::Exception2) = 0; + virtual std::string ping(int excp) 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; }; @@ -198,7 +204,7 @@ public: class Bar { public: Bar(Foo* d) { delegate=d; } - virtual std::string ping(int excp) TESTCASE_THROW(int,MyNS::Exception2) + virtual std::string ping(int excp) throw(int,MyNS::Exception2) { return delegate->ping(excp); }