mirror of https://github.com/swig/swig
Use SWIG_NOEXCEPT for deprecated dynamic exception specifications
SWIG_NOEXCEPT is generated instead of throw() which is deprecated in c++11. If c++11 or later is being used, then this macro expands to noexcept instead of throw(). Affects director code only. Also fix up some testcase to not use throw() when using c++11 or later. Tested with clang and -Wdeprecated-dynamic-exception-spec as gcc doesn't seem to warn for this deprecation. Closes #3027
This commit is contained in:
parent
deadb05bd6
commit
f91a9cb8e4
|
@ -7,6 +7,12 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
|
|||
Version 4.4.0 (in progress)
|
||||
===========================
|
||||
|
||||
2025-04-29: r-barnes, wsfulton
|
||||
#3027 Remove generation of empty dynamic exception specifications - throw(),
|
||||
which are deprecated in c++11. This was only when using the director feature.
|
||||
A new macro SWIG_NOEXCEPT is used which ensures that throw() or noexcept is
|
||||
used for the appropriate C++ standard that the compiler is compiling for.
|
||||
|
||||
2025-04-28: jschueller, henryiii
|
||||
[Python] #2967 Use __spec__.parent as the first approach to obtaining
|
||||
a module's package name when importing the low-level C/C++ module as the
|
||||
|
|
|
@ -107,11 +107,11 @@ struct moveonly {
|
|||
};
|
||||
|
||||
struct ConstructorThrow {
|
||||
ConstructorThrow() throw() = default;
|
||||
ConstructorThrow(const ConstructorThrow&) throw() = delete;
|
||||
ConstructorThrow(ConstructorThrow&&) throw() = delete;
|
||||
ConstructorThrow& operator=(const ConstructorThrow&) throw() = delete;
|
||||
~ConstructorThrow() throw() = default;
|
||||
ConstructorThrow() noexcept = default;
|
||||
ConstructorThrow(const ConstructorThrow&) noexcept = delete;
|
||||
ConstructorThrow(ConstructorThrow&&) noexcept = delete;
|
||||
ConstructorThrow& operator=(const ConstructorThrow&) noexcept = delete;
|
||||
~ConstructorThrow() noexcept = default;
|
||||
};
|
||||
|
||||
%}
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
%feature("director") Bar;
|
||||
|
||||
%{
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#if defined(__cplusplus) && __cplusplus >=201103L
|
||||
#define throw() noexcept
|
||||
#endif
|
||||
%}
|
||||
|
||||
|
|
|
@ -28,10 +28,10 @@ namespace Swig {
|
|||
DirectorException(const std::string &msg) : swig_msg(msg) {
|
||||
}
|
||||
|
||||
virtual ~DirectorException() throw() {
|
||||
virtual ~DirectorException() SWIG_NOEXCEPT {
|
||||
}
|
||||
|
||||
const char *what() const throw() {
|
||||
const char *what() const SWIG_NOEXCEPT {
|
||||
return swig_msg.c_str();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -26,10 +26,10 @@ namespace Swig {
|
|||
DirectorException(const std::string &msg) : swig_msg(msg) {
|
||||
}
|
||||
|
||||
virtual ~DirectorException() throw() {
|
||||
virtual ~DirectorException() SWIG_NOEXCEPT {
|
||||
}
|
||||
|
||||
const char *what() const throw() {
|
||||
const char *what() const SWIG_NOEXCEPT {
|
||||
return swig_msg.c_str();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -428,12 +428,12 @@ namespace Swig {
|
|||
DirectorException(const char *msg) : jenv_(SWIG_NULLPTR), throwable_(SWIG_NULLPTR), classname_(SWIG_NULLPTR), msg_(msg ? copystr(msg) : SWIG_NULLPTR) {
|
||||
}
|
||||
|
||||
~DirectorException() throw() {
|
||||
~DirectorException() SWIG_NOEXCEPT {
|
||||
delete[] classname_;
|
||||
delete[] msg_;
|
||||
}
|
||||
|
||||
const char *what() const throw() {
|
||||
const char *what() const SWIG_NOEXCEPT {
|
||||
return msg_ ? msg_ : "Unspecified DirectorException message";
|
||||
}
|
||||
|
||||
|
|
|
@ -20,10 +20,10 @@ namespace Swig {
|
|||
DirectorException(const char *msg="") : swig_msg(msg) {
|
||||
}
|
||||
|
||||
virtual ~DirectorException() throw() {
|
||||
virtual ~DirectorException() SWIG_NOEXCEPT {
|
||||
}
|
||||
|
||||
const char *what() const throw() {
|
||||
const char *what() const SWIG_NOEXCEPT {
|
||||
return swig_msg.c_str();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -151,7 +151,7 @@ namespace Swig {
|
|||
SvREFCNT_inc(err);
|
||||
}
|
||||
|
||||
const char *what() const throw() {
|
||||
const char *what() const SWIG_NOEXCEPT {
|
||||
return SvPV_nolen(err);
|
||||
}
|
||||
|
||||
|
@ -172,10 +172,10 @@ namespace Swig {
|
|||
}
|
||||
|
||||
public:
|
||||
virtual ~DirectorWrapException() throw() {
|
||||
virtual ~DirectorWrapException() SWIG_NOEXCEPT {
|
||||
}
|
||||
|
||||
const char *what() const throw() {
|
||||
const char *what() const SWIG_NOEXCEPT {
|
||||
return msg.c_str();
|
||||
}
|
||||
|
||||
|
|
|
@ -136,10 +136,10 @@ namespace Swig {
|
|||
if (!EG(exception)) zend_throw_exception(NULL, swig_msg.c_str(), code);
|
||||
}
|
||||
|
||||
virtual ~DirectorException() throw() {
|
||||
virtual ~DirectorException() SWIG_NOEXCEPT {
|
||||
}
|
||||
|
||||
const char *what() const throw() {
|
||||
const char *what() const SWIG_NOEXCEPT {
|
||||
return swig_msg.c_str();
|
||||
}
|
||||
|
||||
|
|
|
@ -177,7 +177,7 @@ namespace Swig {
|
|||
SWIG_PYTHON_THREAD_END_BLOCK;
|
||||
}
|
||||
|
||||
virtual ~DirectorException() throw() {
|
||||
virtual ~DirectorException() SWIG_NOEXCEPT {
|
||||
}
|
||||
|
||||
/* Deprecated, use what() instead */
|
||||
|
@ -185,7 +185,7 @@ namespace Swig {
|
|||
return what();
|
||||
}
|
||||
|
||||
const char *what() const throw() {
|
||||
const char *what() const SWIG_NOEXCEPT {
|
||||
return swig_msg.c_str();
|
||||
}
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ namespace Swig {
|
|||
}
|
||||
|
||||
public:
|
||||
virtual ~DirectorException() throw() {
|
||||
virtual ~DirectorException() SWIG_NOEXCEPT {
|
||||
}
|
||||
|
||||
VALUE getType() const {
|
||||
|
@ -148,7 +148,7 @@ namespace Swig {
|
|||
return swig_msg;
|
||||
}
|
||||
|
||||
const char *what() const throw() {
|
||||
const char *what() const SWIG_NOEXCEPT {
|
||||
return swig_msg.c_str();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -124,6 +124,8 @@
|
|||
|
||||
#if defined(__cplusplus) && __cplusplus >=201103L
|
||||
# define SWIG_NULLPTR nullptr
|
||||
# define SWIG_NOEXCEPT noexcept
|
||||
#else
|
||||
# define SWIG_NULLPTR NULL
|
||||
# define SWIG_NOEXCEPT throw()
|
||||
#endif
|
||||
|
|
|
@ -2191,7 +2191,10 @@ int Language::classDirectorDestructor(Node *n) {
|
|||
*/
|
||||
File *f_directors = Swig_filebyname("director");
|
||||
File *f_directors_h = Swig_filebyname("director_h");
|
||||
if (Getattr(n, "throw")) {
|
||||
if (Getattr(n, "noexcept")) {
|
||||
Printf(f_directors_h, " virtual ~%s() noexcept;\n", DirectorClassName);
|
||||
Printf(f_directors, "%s::~%s() noexcept {\n}\n\n", DirectorClassName, DirectorClassName);
|
||||
} else if (Getattr(n, "throw")) {
|
||||
Printf(f_directors_h, " virtual ~%s() throw();\n", DirectorClassName);
|
||||
Printf(f_directors, "%s::~%s() throw() {\n}\n\n", DirectorClassName, DirectorClassName);
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue