test-suite support for C++17 (Java): exception specification throw removal

This commit is contained in:
William S Fulton 2018-05-03 19:10:50 +01:00
commit 63f7315c8a
2 changed files with 29 additions and 17 deletions

View file

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

View file

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