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

11 Classes [class]

11.4 Class members [class.mem]

11.4.4 Constructors [class.ctor]

11.4.4.1 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 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 istrivialif it is not user-provided and if:

Otherwise, the default constructor isnon-trivial.

A default constructor that is defaulted and not defined as deleted isimplicitly definedwhen it is odr-used ([basic.def.odr]) to create an object of its class type ([intro.object]), when it is needed for constant evaluation ([expr.const]), or when it is explicitly defaulted after its first declaration.

The implicitly-defined default constructor performs the set of initializations of the class that would be performed by a user-written default constructor for that class with noctor-initializer and an emptycompound-statement.

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

If that user-written default constructor would satisfy the requirements of a constexpr constructor ([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

:

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

]

A program is ill-formed if the default constructor for an object is implicitly used and the constructor is not accessible ([class.access]).

[ Note

:

[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

]