[exception] warning about non-virtual destructor - resolution?

Hello, GCC 4.7 introduces a new warning [1] that warns about calling "delete" on a pointer of a type that has virtual functions but a nonvirtual destructor. This warning is enabled with -Wall. As a result, even something as trivial as the following: #include <boost/thread/future.hpp> when compiled with -Wall, produces a warning like this: In file included from boost/boost/smart_ptr/shared_ptr.hpp:30:0, from boost/boost/shared_ptr.hpp:17, from boost/boost/date_time/time_clock.hpp:17, from boost/boost/thread/thread_time.hpp:9, from boost/boost/thread/future.hpp:13, from Source/timetable.cpp:1: boost/boost/checked_delete.hpp: In instantiation of 'void boost::checked_delete(T*) [with T = boost::error_info<boost::tag_original_exception_type, const std::type_info*>]': boost/boost/smart_ptr/detail/shared_count.hpp:95:13: required from 'boost::detail::shared_count::shared_count(Y*) [with Y = boost::error_info<boost::tag_original_exception_type, const std::type_info*>]' boost/boost/smart_ptr/shared_ptr.hpp:177:50: required from 'boost::shared_ptr<T>::shared_ptr(Y*) [with Y = boost::error_info<boost::tag_original_exception_type, const std::type_info*>; T = boost::error_info<boost::tag_original_exception_type, const std::type_info*>]' boost/boost/exception/info.hpp:171:69: required from 'const E& boost::exception_detail::set_info(const E&, const boost::error_info<Tag, T>&) [with E = boost::unknown_exception; Tag = boost::tag_original_exception_type; T = const std::type_info*]' boost/boost/exception/info.hpp:192:46: required from 'typename boost::enable_if<boost::exception_detail::derives_boost_exception<E>, const E&>::type boost::operator<<(const E&, const boost::error_info<Tag, T>&) [with E = boost::unknown_exception; Tag = boost::tag_original_exception_type; T = const std::type_info*; typename boost::enable_if<boost::exception_detail::derives_boost_exception<E>, const E&>::type = const boost::unknown_exception&]' boost/boost/exception/detail/exception_ptr.hpp:182:13: required from 'void boost::unknown_exception::add_original_type(const E&) [with E = std::exception]' boost/boost/exception/detail/exception_ptr.hpp:161:32: required from here boost/boost/checked_delete.hpp:34:5: warning: deleting object of polymorphic class type 'boost::error_info<boost::tag_original_exception_type, const std::type_info*>' which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor] Note that the same code compiled without warnings with GCC 4.6. I've read this thread [2] about this issue, but it's not clear what the agreed-upon resolution was. In light of this new warning, can the code be revised to avoid it? Or is it the position of the library maintainers that GCC is in error to give a warning in this case, in which case I should file a GCC bug? Or is there some other recommended resolution? Thanks, Nate [1] http://gcc.gnu.org/gcc-4.7/changes.html#cxx [2] http://boost.2283326.n4.nabble.com/boost-exception-detail-error-info-base-do...

On Thu, Feb 16, 2012 at 1:50 AM, Nathan Ridge <zeratul976@hotmail.com> wrote:
Or is it the position of the library maintainers that GCC is in error to give a warning in this case, in which case I should file a GCC bug?
I do believe that the compiler is in error to warn about this, since it complains about conscious and correct design decision. Given the fact that the base destructor is protected, the possibility of an error is remote at best. That said, I am have tried to remove all warnings from GCC. The Boost Exception headers use the system header pragmas which in theory should inhibit all warnings within the library. Last time I checked that was the case indeed, including with -Wall. Thank you for the report, I'll take a look again when time permits. Can you provide an exact command line? Thanks, Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode

Or is it the position of the library maintainers that GCC is in error to give a warning in this case, in which case I should file a GCC bug?
I do believe that the compiler is in error to warn about this, since it complains about conscious and correct design decision. Given the fact that the base destructor is protected, the possibility of an error is remote at best.
That said, I am have tried to remove all warnings from GCC. The Boost Exception headers use the system header pragmas which in theory should inhibit all warnings within the library. Last time I checked that was the case indeed, including with -Wall.
Thank you for the report, I'll take a look again when time permits. Can you provide an exact command line?
Certainly. Code: #include <boost/thread/future.hpp> Command line: g++ -c test.cpp -Wall -I /path/to/boost GCC version: 4.7.0, 2012-01-28 snapshot Boost revision: 76729 Let me know if you need any more information. Thanks, Nate
participants (2)
-
Emil Dotchevski
-
Nathan Ridge