-Wnon-virtual-dtor warnings with gcc
trilader opened this issue · comments
There are some warnings when compiling a program which includes cpptoml.h and tries to parse a file.
GCC version is 7.1.1
The warnings can be silenced by temporarily disabling the warning:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
#include "cpptoml.h"
#pragma GCC diagnostic pop
Here is an example of the warnings produced by gcc:
In file included from ../main.cpp:18:0:
../cpptoml.h:404:7: warning: ‘class cpptoml::base’ has virtual functions and accessible non-virtual destructor [-Wnon-virtual-dtor]
class base : public std::enable_shared_from_this<base>
^~~~
../cpptoml.h: In instantiation of ‘class cpptoml::value<long int>’:
../cpptoml.h:571:56: required from here
../cpptoml.h:492:7: warning: base class ‘class cpptoml::base’ has accessible non-virtual destructor [-Wnon-virtual-dtor]
class value : public base
^~~~~
../cpptoml.h:492:7: warning: ‘class cpptoml::value<long int>’ has virtual functions and accessible non-virtual destructor [-Wnon-virtual-dtor]
../cpptoml.h:612:7: warning: base class ‘class cpptoml::base’ has accessible non-virtual destructor [-Wnon-virtual-dtor]
The full warning list can be found at https://gist.github.com/trilader/9bd5b53ce61c6fe43979aa9ad5b6cead
GCC documentation for this warning
-Wnon-virtual-dtor (C++ and Objective-C++ only)
Warn when a class has virtual functions and an accessible non-virtual destructor itself or in an accessible polymorphic base class, in which case it is possible but unsafe to delete an instance of a derived class through a pointer to the class itself or base class. This warning is automatically enabled if -Weffc++ is specified.
If you want to issue a PR to fix this, it should be as simple as adding
virtual ~base() = default;
to the base
class. Otherwise, I'll fix this soon. Thanks for the report!