This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 119a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2025-12-20
[Voted into WP at March, 2010 meeting as part of document N3079.]
Should the following class have a trivial copy assignment operator?
struct A { int& m; A(); A(const A&); };11.4.5.3 [class.copy.ctor] paragraph 11 does not mention whether thepresence of reference members (or cv-qualifiers, etc.) should affecttriviality. Should it?
One reason why this matters is that implementations have to makethe builtin type trait operator__has_trivial_default_ctor(T)work so that they can support the type trait templatestd::has_trivial_default_constructor.
Assuming the answer is “yes,” it looks like we probablyneed similar wording for trivial default and trivial copy ctors.
Notes from the February, 2008 meeting:
Deleted special member functions are also not trivial. Resolutionof this issue should be coordinated with the concepts proposal.
Notes from the June, 2008 meeting:
It appears that this issue will be resolved by the conceptsproposal directly. The issue is in “review” status tocheck if that is indeed the case in the final version of theproposal.
Additional notes (May, 2009):
Consider the following example:
struct Base { private: ~Base() = default; }; struct Derived: Base { };The implicitly-declared destructor ofDerived isdefined as deleted becauseBase::~Base() is inaccessible,but it fulfills the requirements for being trivial. PresumablytheBase destructor should be non-trivial, either bydirectly specifying that it is non-trivial or by specifying that itis user-provided. An alternative would be to make it ill-formed toattempt to declare a defaulted non-public special member function.
Any changes to the definition of triviality should be checkedagainst Clause 11 [class] paragraph 6 for any changes neededthere to accommodate the new definitions.
Notes from the July, 2009 meeting:
The July, 2009 resolution ofissue 906addresses the example above (with an inaccessible defaulteddestructor): a defaulted special member function can only havenon-public access if the defaulted definition is outside the class,making it non-trivial. The example as written above would beill-formed.
Proposed resolution (October, 2009):
Change 9.6 [dcl.fct.def] paragraph 9 as follows:
...Only special member functions may be explicitly defaulted.Explicitly-defaulted functions and implicitly-declared functions arecollectively calleddefaulted functions, and theimplementation shalldefine them as if they hadprovide implicit definitionsfor them(11.4.5 [class.ctor], 11.4.7 [class.dtor], 11.4.5.3 [class.copy.ctor]), which might mean defining them as deleted. Aspecial member function that would be implicitly defined as deletedmay be explicitly defaulted only on its first declaration, in whichcase it is defined as deleted. A special member function isuser-provided if it is user-declared and not explicitlydefaulted on its first declaration. A user-providedexplicitly-defaulted function is defined at the point where it isexplicitly defaulted. [Note:...
Change 11.4.5 [class.ctor] paragraphs 5-6 as follows:
Adefault constructor for a classX is aconstructor of classX that can be called without anargument. If there is no user-declared constructor for classX, a constructor having no parameters is implicitly declaredas defaulted (9.6 [dcl.fct.def]). Animplicitly-declared default constructor is aninline publicmember of its class.
A default constructor istrivial if it is not user-provided (9.6 [dcl.fct.def])and if:
its class has no virtual functions (11.7.3 [class.virtual]) and no virtual base classes (11.7.2 [class.mi]),and
no non-static data member of its class has abrace-or-equal-initializer, and
all the direct base classes of its class have trivial defaultconstructors, and
for all the non-static data members of its class that are ofclass type (or array thereof), each such class has a trivial defaultconstructor.A
n implicitly-declareddefaulted defaultconstructor for classX is defined as deleted if:
X is a union-like class that has a variant memberwith a non-trivial default constructor,
any non-static data member is of reference type,
any non-static data member of const-qualifiedtype (or array thereof) does not have a user-provided defaultconstructor, or
any non-static data member or direct or virtual base class hasclass typeM (or array thereof) andM has no defaultconstructor, or if overload resolution (12.2 [over.match]) asapplied toM's default constructor, results in an ambiguityor a function that is deleted or inaccessible from theimplicitly-declared default constructor.
A default constructor is trivial if it is neitheruser-provided nor deleted and if:
its class has no virtual functions (11.7.3 [class.virtual]) and no virtual base classes (11.7.2 [class.mi]),and
no non-static data member of its class has abrace-or-equal-initializer, and
all the direct base classes of its class have trivial defaultconstructors, and
for all the non-static data members of its class that are ofclass type (or array thereof), each such class has a trivial defaultconstructor.
Otherwise, the default constructor isnon-trivial.
A
non-user-provideddefault constructorfor aclassthat is defaulted and not deleted isimplicitly defined when it is used (6.3 [basic.def.odr])to create an object of its class type (6.8.2 [intro.object]),or when it is explicitly defaulted after its first declaration.The implicitly-definedor explicitly-defaulteddefaultconstructor performs the set of initializations of the class thatwould be performed by a user-written default constructor for thatclass with noctor-initializer (11.9.3 [class.base.init])and an emptycompound-statement. If that user-written defaultconstructor would be ill-formed, the program is ill-formed. If thatuser-written default constructor would satisfy the requirements of aconstexpr constructor (9.2.6 [dcl.constexpr]), theimplicitly-defined default constructor is constexpr. Before thenon-user-provideddefaulted default constructorfor a class is implicitly defined, all the non-user-provided defaultconstructors for its base classes and its non-static data membersshall have been implicitly defined. [Note: animplicitly-declared default constructor has anexception-specification (14.5 [except.spec]). Anexplicitly-defaulted definition has no implicitexception-specification. —end note]
Change 11.4.7 [class.dtor] paragraphs 3-4 as follows:
If a class has no user-declared destructor, a destructor is
declaredimplicitlydeclared as defaulted(9.6 [dcl.fct.def]). An implicitly-declared destructor isaninline public member of its class.If the class is aunion-like class that has a variant member with a non-trivialdestructor, an implicitly-declared destructor is defined as deleted(9.6 [dcl.fct.def]). A destructor istrivial if it isnot user-provided and if:
the destructor is notvirtual,
all of the direct base classes of its class have trivialdestructors, and
for all of the non-static data members of its class that are ofclass type (or array thereof), each such class has a trivialdestructor.A
n implicitly-declareddefaulted destructorfor a classX is defined as deleted if:
X is a union-like class that has a variant memberwith a non-trivial destructor,
any of the non-static data members has class typeM(or array thereof) andM has
anadeleted destructor or a destructor that is inaccessible from theimplicitly-declared destructor, orany direct or virtual base class has a deleted destructor or adestructor that is inaccessible from the implicitly-declareddestructor.
A destructor is trivial if it is neither user-provided nordeleted and if:
the destructor is notvirtual,
all of the direct base classes of its class have trivialdestructors, and
for all of the non-static data members of its class that are ofclass type (or array thereof), each such class has a trivialdestructor.
Otherwise, the destructor isnon-trivial.
A
non-user-provideddestructorthat is defaultedand not defined as deleted isimplicitly defined when itis used to destroy an object of its class type (6.8.6 [basic.stc]), or when it is explicitly defaulted after its firstdeclaration.A program is ill-formed if the class for which adestructor is implicitly defined or explicitly defaulted has:
a non-static data member of class type (or array thereof)with an inaccessible destructor, or
a base class with an inaccessible destructor.Before the
non-user-provideddefaulteddestructor for a class is implicitly defined, all thenon-user-definednon-user-provided destructorsfor its base classes and its non-static data members shall have beenimplicitly defined. [Note: an implicitly-declared destructorhas anexception-specification (14.5 [except.spec]). Anexplictly defaulted definition has no implicitexception-specification. —end note]
Change 11.4.5.3 [class.copy.ctor] paragraphs 4-9 as follows:
If the class definition does not explicitly declare a copyconstructor, one is
declaredimplicitlyimplicitly declared as defaulted (9.6 [dcl.fct.def]). Thus......An implicitly-declared copy constructor is aninlinepublic member of its class. A
n implicitly-declareddefaulted copy constructor for a classX isdefined as deleted ifX has: ...A copy constructor for classX is
trivialtrivial if it isnotneither user-providednor deleted(9.6 [dcl.fct.def])and if...A
non-user-providedcopy constructorthat isdefaulted and not defined as deleted isimplicitlydefined if it is used to initialize an object of its class typefrom a copy of an object of its class type or of a class type derivedfrom its class type116, or when it is explicitlydefaulted after its first declaration. [Note: the copyconstructor is implicitly defined even if the implementation elidedits use (6.8.7 [class.temporary]). —end note]Before the
non-user-provideddefaulted copyconstructor for a class is implicitly defined, all non-user-providedcopy constructors...The implicitly-defined
or explicitly-defaultedcopyconstructor for a non-union classX performs...The implicitly-defined
or explicitly-defaultedcopyconstructor for a unionX copies the object representation(6.9 [basic.types]) ofX.
Change 11.4.5.3 [class.copy.ctor] paragraphs 11-15 as follows:
If the class definition does not explicitly declare a copyassignment operator, one is
declaredimplicitlyimplicitly declared as defaulted (9.6 [dcl.fct.def])......A
n implicitly-declareddefaulted copyassignment operator for classX is defined as deleted ifX has:...A copy assignment operator for classX istrivialif it is
notneither user-providednordeleted and if...A
non-user-providedcopy assignment operatorthatis defaulted and not defined as deleted isimplicitlydefined when an object of its class type is assigned a value ofits class type or a value of a class type derived from its classtype, or when it is explicitly defaulted after its firstdeclaration.Before the
non-user-provideddefaulted copyassignment operator for a class is implicitly defined...The implicitly-defined
or explicitly-defaultedcopyassignment operator for a non-union classX performs...It is unspecified whether subobjects representing virtual baseclasses are assigned more than once by the implicitly-defined
orexplicitly-defaultedcopy assignmentoperator. [Example:...The implicitly-defined
or explicitly-defaultedcopyassignment operator for a unionX copies the objectrepresentation (6.9 [basic.types]) ofX.