Title
Deleted subobject destructors and implicitly-defined constructors
Status
c++11
Section
11.4.5 [class.ctor]
Submitter
Jason Merrill

Created on 2010-09-02.00:00:00 last changed 131 months ago

Messages

Date: 2011-03-15.00:00:00

[Voted into the WP at the March, 2011 meeting.]

Date: 2011-01-15.00:00:00

Proposed resolution (January, 2011):

  1. Add a new bullet to 11.4.5 [class.ctor] paragraph 5 as follows:

  2. ...A defaulted default constructor for class X is defined as deleted if:

    • ...

    • X is a non-union class and all members of any anonymous union member are of const-qualified type (or array thereof), or

    • any direct or virtual base class, or non-static data member with no brace-or-equal-initializer, has class type M (or array thereof) and either M has no default constructor or overload resolution (12.2 [over.match]) as applied to M's default constructor results in an ambiguity or in a function that is deleted or inaccessible from the defaulted default constructor., or

    • any direct or virtual base class or non-static data member has a type with a destructor that is deleted or inaccessible from the defaulted default constructor.

  3. Add a new bullet to 11.4.5.3 [class.copy.ctor] paragraph 12 as follows:

  4. ...A defaulted copy/move constructor for a class X is defined as deleted (9.5.3 [dcl.fct.def.delete]) if X has:

    • a variant member with a non-trivial corresponding constructor and X is a union-like class,

    • a non-static data member of class type M (or array thereof) that cannot be copied/moved because overload resolution (12.2 [over.match]), as applied to M's corresponding constructor, results in an ambiguity or a function that is deleted or inaccessible from the defaulted constructor, or

    • a direct or virtual base class B that cannot be copied/moved because overload resolution (12.2 [over.match]), as applied to B's corresponding constructor, results in an ambiguity or a function that is deleted or inaccessible from the defaulted constructor, or

    • any direct or virtual base class or non-static data member of a type with a destructor that is deleted or inaccessible from the defaulted constructor,

    • for the copy constructor, a non-static data member of rvalue reference type, or

    • for the move constructor, a non-static data member or direct or virtual base class with a type that does not have a move constructor and is not trivially copyable.

Date: 2010-11-15.00:00:00

Notes from the November, 2010 meeting:

The CWG agreed that a change was needed, but only if one or more base and/or member constructors are non-trivial.

Date: 2022-02-18.07:47:23

Consider the following example:

    struct A {
       A();
       ~A() = delete;
    };

    struct B: A { };
    B* b = new B;

Under the current rules, B() is not deleted, but is ill-formed because it calls the deleted ~A::A() if it exits via an exception after the completion of the construction of A. A deleted subobject destructor should be added to the list of reasons for implicit deletion in 11.4.5 [class.ctor] and 11.4.5.3 [class.copy.ctor].

History
Date User Action Args
2014-03-03 00:00:00adminsetstatus: fdis -> c++11
2011-04-10 00:00:00adminsetmessages: + msg3362
2011-04-10 00:00:00adminsetstatus: tentatively ready -> fdis
2011-02-28 00:00:00adminsetmessages: + msg3234
2011-02-28 00:00:00adminsetstatus: drafting -> tentatively ready
2010-11-29 00:00:00adminsetmessages: + msg3124
2010-11-29 00:00:00adminsetstatus: open -> drafting
2010-09-02 00:00:00admincreate