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

2024-04-18


1051. Reference members and generated copy constructors

Section: 11.4.5.3  [class.copy.ctor]     Status: C++11     Submitter: Steve Adamczyk     Date: 2010-03-11

[Voted into the WP at the November, 2010 meeting.]

N3092 comment US 62

The new wording describing generated copy constructors (11.4.5.3 [class.copy.ctor] paragraph 16) does not describe the initialization of members with reference type.

See also issue 992.

Proposed resolution (October, 2010):

  1. Change 11.4.5.3 [class.copy.ctor] paragraph 12 as follows:

  2. An implicitly-declared copy/move constructor is an inline public member of its class. A defaulted copy/move constructor for a class X is defined as deleted (9.5.3 [dcl.fct.def.delete]) if X has:

  3. Change 11.4.5.3 [class.copy.ctor] paragraph 16 as follows:

  4. The implicitly-defined copy/move constructor for a non-union class X performs a memberwise copy/move of its subobjects bases and members. [Note: brace-or-equal-initializers of non-static data members are ignored. See also the example in 11.9.3 [class.base.init]. —end note] The order of copying initialization is the same as the order of initialization of bases and members in a user-defined constructor (see 11.9.3 [class.base.init]). Let x be either the parameter of the constructor or, for the move constructor, an xvalue referring to the parameter. Each subobject base or non-static data member is copied/moved in the manner appropriate to its type:

    Virtual base class subobjects shall be copied initialized only once by the implicitly-defined copy/move constructor (see 11.9.3 [class.base.init]).

  5. Delete 11.4.5.3 [class.copy.ctor] paragraph 17:

  6. The implicitly-defined move constructor for a non-union class X performs a memberwise move of its subobjects. [Note: brace-or-equal-initializers of non-static data members are ignored. See also the example in 11.9.3 [class.base.init]. —end note] The order of moving is the same as the order of initialization of bases and members in a user-defined constructor (see 11.9.3 [class.base.init]). Given a parameter named x, each base or non-static data member is moved in the manner appropriate to its type:

    Virtual base class subobjects shall be moved only once by the implicitly-defined move constructor (see 11.9.3 [class.base.init]).

  7. Change 11.4.5.3 [class.copy.ctor] paragraph 18 as follows:

  8. The implicitly-defined copy/move constructor for a union X copies the object representation (6.8 [basic.types]) of X.
  9. Change 11.4.5.3 [class.copy.ctor] paragraph 28 as follows:

  10. A copy/move assignment operator that is defaulted and not defined as deleted is implicitly defined when is assigned a value of its class type or a value of a class type derived from its class type it is used (6.3 [basic.def.odr]) (e.g., when it is selected by overload resolution to assign to an object of its class type) or when it is explicitly defaulted after its first declaration.
  11. Change 11.4.5.3 [class.copy.ctor] paragraph 30 as follows:

  12. The implicitly-defined copy/move assignment operator for a non-union class X performs memberwise copy/move assignment of its subobjects. The direct base classes of X are assigned first, in the order of their declaration in the base-specifier-list, and then the immediate non-static data members of X are assigned, in the order in which they were declared in the class definition. Let x be either the parameter of the function or, for the move assignment operator, an xvalue referring to the parameter. Each subobject is assigned in the manner appropriate to its type:

    It is unspecified whether subobjects representing virtual base classes are assigned more than once by the implicitly-defined copy assignment operator. [Example:

      struct V { };
      struct A : virtual V { };
      struct B : virtual V { };
      struct C : B, A { };
    

    It is unspecified whether the virtual base class subobject V is assigned twice by the implicitly-defined copy assignment operator for C. —end example] [Note: This does not apply to move assignment, as a defaulted move assignment operator is deleted if the class has virtual bases. —end note]

  13. Delete 11.4.5.3 [class.copy.ctor] paragraph 31:

  14. The implicitly-defined move assignment operator for a non-union class X performs memberwise assignment of its subobjects. The direct base classes of X are assigned first, in the order of their declaration in the base-specifier-list, and then the immediate non-static data members of X are assigned, in the order in which they were declared in the class definition. Given a parameter named x, each subobject is assigned in the manner appropriate to its type:

This resolution also resolves issues 1020, 1064 and 1066.