Jens Maurer
2010-11-11
N3204=10-0194

Deducing "noexcept" for destructors

This proposed wording implements Alisdair's rules for deducing "noexcept" on destructors, addressing FCD national body comments FI 17 and GB 40. It is a follow-up paper to N3166=10-0156 "Destructors default to noexcept" by David Svoboda, which suggested to mark all destructors "noexcept(true)" unconditionally.

The motivating example is:

template<class T, class U>
class C : public T {
  U u;
  ~C() { ... }
};
Unless an explicit "noexcept" annotation is given, the destructor C::~C() should be "noexcept(true)" if none of the base or member destructors is "noexcept(false)", regardless of the contents of the destructor's function-body.

Add a new paragraph after 12.4 class.dtor paragraph 2:

A declaration of a destructor that does not have an exception-specification is implicitly considered to have the same exception-specification as an implicit declaration (15.4 except.spec).
Change in 12.4 class.dtor paragraph 5:
Before the defaulted destructor for a class is implicitly defined, all the non-user-provided destructors for its base classes and its non-static data members shall have been implicitly defined. [ Note: an implicitly-declared destructor has an exception-specification (15.4 except.spec). An explictly defaulted definition has no implicit exception-specification. -- end note ]