mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-26 07:02:11 +00:00
clang -Wnon-virtual-dtor compatibility (#2626)
* Adding missing virtual destructors, to silence clang -Wnon-virtual-dtor warnings. Tested with clang version 9.0.1-12 under an Ubuntu-like OS. Originally discovered in the Google-internal environment. * adding -Wnon-virtual-dtor for GNU|Intel|Clang
This commit is contained in:
parent
f2e799863b
commit
8290a5a0da
@ -243,8 +243,15 @@ function(pybind11_enable_warnings target_name)
|
|||||||
if(MSVC)
|
if(MSVC)
|
||||||
target_compile_options(${target_name} PRIVATE /W4)
|
target_compile_options(${target_name} PRIVATE /W4)
|
||||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Intel|Clang)" AND NOT PYBIND11_CUDA_TESTS)
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Intel|Clang)" AND NOT PYBIND11_CUDA_TESTS)
|
||||||
target_compile_options(${target_name} PRIVATE -Wall -Wextra -Wconversion -Wcast-qual
|
target_compile_options(
|
||||||
-Wdeprecated -Wundef)
|
${target_name}
|
||||||
|
PRIVATE -Wall
|
||||||
|
-Wextra
|
||||||
|
-Wconversion
|
||||||
|
-Wcast-qual
|
||||||
|
-Wdeprecated
|
||||||
|
-Wundef
|
||||||
|
-Wnon-virtual-dtor)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(PYBIND11_WERROR)
|
if(PYBIND11_WERROR)
|
||||||
|
@ -117,7 +117,11 @@ TEST_SUBMODULE(callbacks, m) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
class AbstractBase { public: virtual unsigned int func() = 0; };
|
class AbstractBase {
|
||||||
|
public:
|
||||||
|
virtual ~AbstractBase() = default;
|
||||||
|
virtual unsigned int func() = 0;
|
||||||
|
};
|
||||||
m.def("func_accepting_func_accepting_base", [](std::function<double(AbstractBase&)>) { });
|
m.def("func_accepting_func_accepting_base", [](std::function<double(AbstractBase&)>) { });
|
||||||
|
|
||||||
struct MovableObject {
|
struct MovableObject {
|
||||||
|
@ -32,6 +32,13 @@ class MyException3 {
|
|||||||
public:
|
public:
|
||||||
explicit MyException3(const char * m) : message{m} {}
|
explicit MyException3(const char * m) : message{m} {}
|
||||||
virtual const char * what() const noexcept {return message.c_str();}
|
virtual const char * what() const noexcept {return message.c_str();}
|
||||||
|
// Rule of 5 BEGIN: to preempt compiler warnings.
|
||||||
|
MyException3(const MyException3&) = default;
|
||||||
|
MyException3(MyException3&&) = default;
|
||||||
|
MyException3& operator=(const MyException3&) = default;
|
||||||
|
MyException3& operator=(MyException3&&) = default;
|
||||||
|
virtual ~MyException3() = default;
|
||||||
|
// Rule of 5 END.
|
||||||
private:
|
private:
|
||||||
std::string message = "";
|
std::string message = "";
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user