Boost logo

Boost :

Subject: Re: [boost] [exception] warning about non-virtual destructor - resolution?
From: Daniel James (dnljms_at_[hidden])
Date: 2012-04-15 15:56:34


On 15 April 2012 13:53, Mathias Gaunard <mathias.gaunard_at_[hidden]> wrote:
>
> 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.

But shared_ptr is explicitly written to deal with this case so the
warning is almost always incorrect (remember that if you delete the
object by some other means, the warning will appear for the other
deletion). You can see this tested in shared_ptr_test. Look at the
contents of n_spt_abstract (in a couple of places). Note also that
gcc's std::shared_ptr does not warn for this use case.

> 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...

This isn't just about Boost.Exception. I'm not arguing against it
making its destructor virtual.

> It would also have the advantage of not relying on fragile compiler-specific
> warning suppression mechanisms.

Since this warning was added in 4.7, the warning mechanism introduced
in 4.6 can be used. It isn't fragile.

> As a rule, rewriting the code so that the warning doesn't happen is much
> more valuable than disabling the warning.

Sometimes that's that case, but sometimes the opposite is true.
Rewriting code can cause unnecessary complexity and introduce bugs.
Especially when you consider the multitude of warnings we have to deal
with.


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