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

Created on 2014-04-15.00:00:00 last changed 72 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.

Date: 2014-04-15.00:00:00

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

In a non-delegating constructor, the destructor for each potentially constructed subobject of class type is potentially invoked (15.4 [class.dtor]). [Note: This provision ensures that destructors can be called for fully-constructed sub-objects in case an exception is thrown (18.2 [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 base class constructor is non-throwing, the deleted base class destructor need not be referenced.

Suggested resolution:

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

In a non-delegating constructor without a non-throwing exception-specification (18.4 [except.spec]), the destructor for each potentially constructed subobject of class type is potentially invoked (15.4 [class.dtor]). [Note: This provision ensures that destructors can be called for fully-constructed sub-objects in case an exception is thrown (18.2 [except.ctor]) but does not prevent explicitly deleted destructors in the presence of a non-throwing constructor. —end note]
History
Date User Action Args
2014-07-07 00:00:00adminsetmessages: + msg5126
2014-07-07 00:00:00adminsetstatus: open -> extension
2014-04-15 00:00:00admincreate