build: disable `-Wnon-virtual-dtor` compiler warning
It's overkill and suffers from annoying false positives that
prevent us from applying the "protected non-virtual destructor"
idiom in several perfectly valid cases. See for instance the
GCC bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102168
The -Wdelete-non-virtual-dtor warning (included in -Wall) is
the preferred alternative and is enough to catch the unsafe
cases without false positives.
Partially reverts 847de408cbb2358bbb664d971cc33e73b0b2ef7f
Change-Id: I46ee1f01e7d4e2b125c2c534c6550824ba1de4c0
diff --git a/daemon/mgmt/manager-base.hpp b/daemon/mgmt/manager-base.hpp
index 08aca11..d9b351a 100644
--- a/daemon/mgmt/manager-base.hpp
+++ b/daemon/mgmt/manager-base.hpp
@@ -53,9 +53,6 @@
using std::runtime_error::runtime_error;
};
- virtual
- ~ManagerBase();
-
const std::string&
getModule() const
{
@@ -71,6 +68,11 @@
ManagerBase(std::string_view module, Dispatcher& dispatcher,
CommandAuthenticator& authenticator);
+ // ManagerBase is not supposed to be used polymorphically, so we make the destructor
+ // protected to prevent deletion of derived objects through a pointer to the base class,
+ // which would be UB when the destructor is non-virtual.
+ ~ManagerBase();
+
NFD_PUBLIC_WITH_TESTS_ELSE_PROTECTED: // registrations to the dispatcher
// difference from mgmt::ControlCommand: accepts nfd::ControlParameters
using ControlCommandHandler = std::function<void(const ControlCommand& command,