Title
Potentially-invoked destructors in non-throwing constructors
Status
open
Section
11.9.3 [class.base.init]
Submitter
Aaron Ballman

Created on 2014-04-15.00:00:00 last changed 24 months ago

Messages

Date: 2014-06-15.00:00:00

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.

Date: 2022-11-20.07:54:16

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]
Date: 2022-11-24.22:03:43

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.

History
Date User Action Args
2022-11-24 20:56:39adminsetstatus: extension -> open
2022-11-20 07:54:16adminsetmessages: + msg7035
2014-07-07 00:00:00adminsetmessages: + msg5126
2014-07-07 00:00:00adminsetstatus: open -> extension
2014-04-15 00:00:00admincreate