Don't use exception specification with C++ compiler in example
Support for the exception specifications using types was removed in C++17 (and "throw ()" in C++20), so don't use them when using the C++ compiler any longer, as this broke the example with recent g++ versions that use C++17 by default. We still need them for SWIG, however, so use SWIG_THROW macro, defined differently for SWIG and the compiler, to preserve the existing behaviour. Using %except might be a better idea, but would require more changes.
This commit is contained in:
parent
43276f22a7
commit
d2546e23ff
2 changed files with 9 additions and 14 deletions
|
|
@ -3,6 +3,7 @@
|
|||
#ifndef SWIG
|
||||
struct A {
|
||||
};
|
||||
#define SWIG_THROW(...)
|
||||
#endif
|
||||
|
||||
class Exc {
|
||||
|
|
@ -15,38 +16,29 @@ public:
|
|||
char msg[256];
|
||||
};
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
|
||||
class Test {
|
||||
public:
|
||||
int simple() throw(int&) {
|
||||
int simple() SWIG_THROW(int&) {
|
||||
throw(37);
|
||||
return 1;
|
||||
}
|
||||
int message() throw(const char *) {
|
||||
int message() SWIG_THROW(const char *) {
|
||||
throw("I died.");
|
||||
return 1;
|
||||
}
|
||||
int hosed() throw(Exc) {
|
||||
int hosed() SWIG_THROW(Exc) {
|
||||
throw(Exc(42,"Hosed"));
|
||||
return 1;
|
||||
}
|
||||
int unknown() throw(A*) {
|
||||
int unknown() SWIG_THROW(A*) {
|
||||
static A a;
|
||||
throw &a;
|
||||
return 1;
|
||||
}
|
||||
int multi(int x) throw(int, const char *, Exc) {
|
||||
int multi(int x) SWIG_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"));
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,9 @@
|
|||
SWIG_exception(SWIG_RuntimeError, $1.msg);
|
||||
}
|
||||
|
||||
/* This needs to be defined for SWIG, even though it can't be used in C++ any more. */
|
||||
#define SWIG_THROW(...) throw(__VA_ARGS__)
|
||||
|
||||
/* Let's just grab the original header file here */
|
||||
%include "example.h"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue