Boost logo

Boost :

Subject: Re: [boost] [exception] warning about non-virtual destructor - resolution?
From: Hite, Christopher (Christopher.Hite_at_[hidden])
Date: 2012-04-17 07:41:50


Emil Dotchevski wrote:
 
> On Mon, Apr 16, 2012 at 9:14 AM, Hite, Christopher < Christopher.Hite_at_[hidden]> wrote:
> > You're really hard pressed to come up with situations where you would
> > care about an extra virtual table entry and an extra indirection while deleting.

> The reason to care isn't performance. I tend to take the virtual keyword seriously when I read code: it is an invitation to call the function through a base type pointer. In this case it would be a bug if the destructor is ever called virtually. You'll know your compiler is wrong when it tries to "protect" you from conscious and correct design decisions.

Well you did make the dtor protected. That's a pretty strong signal to anyone reading the code that the interface is doesn't include ownership.

Adding a virtual dtor to the child class should aslo make the warning go away too.

> That said, the warning is annoying and I want it gone. I have not been able to reproduce it.

I was able to do the same test as others gcc-4.7.0 Linux.
g++ -c -Wall -I$BOOST_ROOT boost_exceptionwarning.cpp

/fs/tools/L4/boost_1_49_0/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]

Chris


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk