Boost logo

Boost :

Subject: Re: [boost] [C++11] If you have an old class with a throwing destructor...
From: Nevin Liber (nevin_at_[hidden])
Date: 2013-09-09 14:11:48


On 9 September 2013 11:52, Niall Douglas <s_sourceforge_at_[hidden]> wrote:

> On 9 Sep 2013 at 18:41, Andrzej Krzemienski wrote:
>
> > Your analysis is correct, but in practice the problem described by Daryle
> > still exists. Authors of classes that throw in destructors need to take
> > some action if they have written their libraries in C++03: either mark
> > destructors as noexcept(false) or embed a sub-object (member or base
> class)
> > that has a noexcept(false) destructor.
>
> In C++03 it was always best practice to *always* wrap your
> destructors in a try...catch clause.

No; the best practice is not to throw from a destructor.

> As an aside, we could really do with some new compiler warnings on
> this actually.

I'm not sure what the warning would be, as move constructors are allowed to
throw.

> I already get caught enough times forgetting to mark
> move constructors as noexcept, without which some STL implementations
> will silently disable move construction completely.
>

That seems buggy, other than the well-defined cases such as vector using
the equivalent of move_if_noexcept under the covers when growing a vector.

-- 
 Nevin ":-)" Liber  <mailto:nevin_at_[hidden]>  (847) 691-1404

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