Boost logo

Boost :

Subject: [boost] [exception] warning about non-virtual destructor - resolution?
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2012-02-16 04:50:50


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?



Boost list run by bdawes at, gregod at, cpdaniel at, john at