Subject: Re: [boost] [exception] warning about non-virtual destructor - resolution?
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2012-04-15 08:53:07
On 14/04/12 23:13, Daniel James wrote:
> In this case the warning fires because it's triggered by the delete
> command, which is not covered by the system header pragma in the
> exception headers. This is different to the old warning which was
> triggered by the destructor. This might actually be a problem for
> other libraries as well. 'checked_delete' is used by 'shared_ptr' and
> is supposed to be safe for the case when the destructor isn't virtual,
> so this might result in warnings for valid uses of 'shared_ptr'. So,
> for g++ 4.7 and up, the correct solution *might* be to use the new
> pragmas to disable the warning in checked_delete. But it might not,
> I'm not familiar enough with checked_delete to know if that would be
Calling delete on a pointer to a polymorphic type with a non-virtual
destructor might be a bug. It would be a bad idea for shared_ptr to
disable this warning for any other type than error_info.
The simplest solution is to make the destructor of error_info virtual,
since it doesn't add any significant overhead, especially compared to
how bloated Boost.Exception is as a whole...
It would also have the advantage of not relying on fragile
compiler-specific warning suppression mechanisms.
As a rule, rewriting the code so that the warning doesn't happen is much
more valuable than disabling the warning.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk