Requirements for trivial subobject special functions
_N4750_.15.8 [class.copy]
Jens Maurer

Created on 2008-03-13.00:00:00 last changed 162 months ago


Date: 2008-09-15.00:00:00

[Voted into the WP at the September, 2008 meeting (resolution in paper N2757).]

Date: 2008-09-15.00:00:00

Notes from the September, 2008 meeting:

The resolution adopted as part of paper N2757 differs from the July, 2008 proposed resolution by allowing defaulted and user-provided special member functions to coexist. Instead, a trivial class is defined as having no non-trivial copy constructors or copy assignment operators, and a trivial copy constructor or assignment operator is defined as invoking only trivial copy operations for base and member subobjects.

Date: 2008-07-15.00:00:00

Proposed resolution (July, 2008):

Change 9.5 [dcl.fct.def] paragraph 9 as follows:

... A special member function that would be implicitly defined as deleted shall not be explicitly defaulted. If a special member function for a class X is defaulted on its first declaration, no other special member function of the same kind (default constructor, copy constructor, or copy assignment operator) shall be declared in class X. A special member function is user-provided...
Date: 2020-12-15.00:00:00

Part of the decision regarding whether a class has a trivial special function (copy constructor, copy assignment operator, default constructor) is whether its base and member subobjects have corresponding trivial member functions. However, with the advent of defaulted functions, it is now possible for a single class to have both trivial and nontrivial overloads for those functions. For example,

    struct B {
       B(B&) = default;    // trivial
       B(const B&);        // non-trivial, because user-provided

    struct D : B { };

Although B has a trivial copy constructor and thus satisfies the requirements in _N4750_.15.8 [class.copy] paragraph 6, the copy constructor in B that would be called by the implicitly-declared copy constructor in D is not trivial. This could be fixed either by requiring that all the subobject's copy constructors (or copy assignment operators, or default constructors) be trivial or that the one that would be selected by overload resolution be trivial.

Date User Action Args
2008-10-05 00:00:00adminsetmessages: + msg1829
2008-10-05 00:00:00adminsetmessages: + msg1828
2008-10-05 00:00:00adminsetstatus: review -> cd1
2008-07-27 00:00:00adminsetmessages: + msg1727
2008-07-27 00:00:00adminsetstatus: open -> review
2008-03-13 00:00:00admincreate