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/face/network-predicate.hpp b/daemon/face/network-predicate.hpp
index 965ec88..815afcc 100644
--- a/daemon/face/network-predicate.hpp
+++ b/daemon/face/network-predicate.hpp
@@ -40,9 +40,6 @@
public:
NetworkPredicateBase();
- virtual
- ~NetworkPredicateBase();
-
/**
* \brief Set the whitelist to "*" and clear the blacklist.
*/
@@ -59,6 +56,25 @@
assign(std::initializer_list<std::pair<std::string, std::string>> whitelist,
std::initializer_list<std::pair<std::string, std::string>> blacklist);
+protected:
+ // Explicitly declare the following four special member functions
+ // to avoid -Wdeprecated-copy-with-dtor warnings from clang.
+
+ NetworkPredicateBase(const NetworkPredicateBase&) = delete;
+
+ NetworkPredicateBase(NetworkPredicateBase&&) = default;
+
+ NetworkPredicateBase&
+ operator=(const NetworkPredicateBase&) = delete;
+
+ NetworkPredicateBase&
+ operator=(NetworkPredicateBase&&) = default;
+
+ // NetworkPredicateBase 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.
+ ~NetworkPredicateBase() = default;
+
private:
virtual bool
isRuleSupported(const std::string& key) = 0;
@@ -95,7 +111,7 @@
* ndn::net::NetworkInterface is accepted if it matches any entry in the whitelist and none of
* the entries in the blacklist.
*/
-class NetworkInterfacePredicate : public NetworkPredicateBase
+class NetworkInterfacePredicate final : public NetworkPredicateBase
{
public:
bool
@@ -117,7 +133,7 @@
* 2001:db8:2::/64`) or a wildcard (`*`) that matches all IP addresses. An IP address is
* accepted if it matches any entry in the whitelist and none of the entries in the blacklist.
*/
-class IpAddressPredicate : public NetworkPredicateBase
+class IpAddressPredicate final : public NetworkPredicateBase
{
public:
bool