[class.default.ctor] (original) (raw)

11 Classes [class]

11.4 Class members [class.mem]

11.4.5 Constructors [class.ctor]

11.4.5.2 Default constructors [class.default.ctor]

A default constructor for a class Xis a constructor of class Xfor which each parameter that is not a function parameter pack has a default argument (including the case of a constructor with no parameters).

If there is no user-declared constructor or constructor template for classX, a non-explicit constructor having no parameters is implicitly declared as defaulted ([dcl.fct.def]).

An implicitly-declared default constructor is an inline public member of its class.

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

A default constructor for a class X istrivialif it is not user-provided and if

Otherwise, the default constructor isnon-trivial.

If a default constructor of a union-like class X is trivial, then for each union Uthat is either X or an anonymous union member of X, if the first variant member, if any, of Uhas implicit-lifetime type ([basic.types.general]), the default constructor of X begins the lifetime of that member if it is not the active member of its union.

[Note 1:

It is already the active member if U was value-initialized.

— _end note_]

If that user-written default constructor would be ill-formed, the program is ill-formed.

If that user-written default constructor would be constexpr-suitable ([dcl.constexpr]), the implicitly-defined default constructor is constexpr.

Before the defaulted default constructor for a class is implicitly defined, all the non-user-provided default constructors for its base classes and its non-static data members are implicitly defined.

[Note 2:

An implicitly-declared default constructor has an exception specification ([except.spec]).

An explicitly-defaulted definition might have an implicit exception specification, see [dcl.fct.def].

— _end note_]

[Note 3:

A default constructor is implicitly invoked to initialize a class object when no initializer is specified ([dcl.init.general]).

Such a default constructor needs to be accessible ([class.access]).

— _end note_]

[Note 4:

[class.base.init] describes the order in which constructors for base classes and non-static data members are called and describes how arguments can be specified for the calls to these constructors.

— _end note_]