Commit 8290a5a0 by Ralf W. Grosse-Kunstleve Committed by GitHub

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
parent f2e79986
...@@ -243,8 +243,15 @@ function(pybind11_enable_warnings target_name) ...@@ -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) { ...@@ -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 { ...@@ -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 = "";
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment