This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115d. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-10-26


1915. Potentially-invoked destructors in non-throwing constructors

Section: 11.9.3  [class.base.init]     Status: open     Submitter: Aaron Ballman     Date: 2014-04-15     Liaison: EWG

The requirement in 11.9.3 [class.base.init] paragraph 10,

In a non-delegating constructor, the destructor for each potentially constructed subobject of class type is potentially invoked (11.4.7 [class.dtor]). [Note: This provision ensures that destructors can be called for fully-constructed sub-objects in case an exception is thrown (14.3 [except.ctor]). —end note]

is needlessly restrictive, preventing otherwise-reasonable code like

  class Base {
  protected:
    Base(int i) noexcept {}
    Base() = delete;
    ~Base() = delete;
  };

  class Derived : public Base {
  public:
    Derived() noexcept : Base(1) {}
    ~Derived() = delete;
  };

Since the derived class constructor is non-throwing, the deleted base class destructor need not be referenced.

Suggested resolution:

Change 11.9.3 [class.base.init] paragraph 10 as follows:

In a non-delegating constructor without a non-throwing exception-specification (14.5 [except.spec]), the destructor for each potentially constructed subobject of class type is potentially invoked (11.4.7 [class.dtor]). [Note: This provision ensures that destructors can be called for fully-constructed sub-objects in case an exception is thrown (14.3 [except.ctor]) but does not prevent explicitly deleted destructors in the presence of a non-throwing constructor. —end note]

Rationale (June, 2014):

This request for a language change should be evaluated by EWG before any action is taken.

EWG 2022-11-11

This is a defect, but has ABI impact that should be explored in a paper to EWG. This is tracked in github issue cplusplus/papers#1371.