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

This commit is contained in:
William S Fulton 2018-05-03 18:57:46 +01:00
commit 35b792daed
23 changed files with 190 additions and 419 deletions

View file

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