[dcl.fct.def.default] (original) (raw)

9 Declarations [dcl.dcl]

9.5 Function definitions [dcl.fct.def]

9.5.2 Explicitly-defaulted functions [dcl.fct.def.default]

A function definition whosefunction-bodyis of the form= default ;is called an explicitly-defaulted definition.

A function that is explicitly defaulted shall

The type T of an explicitly defaulted special member function Fis allowed to differ from the type T it would have had if it were implicitly declared, as follows:

If T differs from T in any other way, then:

An explicitly-defaulted function that is not defined as deleted may be declaredconstexpr or consteval only if it is constexpr-compatible ([special], [class.compare.default]).

A function explicitly defaulted on its first declaration is implicitly inline ([dcl.inline]), and is implicitly constexpr ([dcl.constexpr]) if it is constexpr-compatible.

[Example 1: struct S { constexpr S() = default; S(int a = 0) = default; void operator=(const S&) = default; ~S() noexcept(false) = default; private: int i; S(S&); }; S::S(S&) = default; struct T { T(); T(T &&) noexcept(false);};struct U { T t; U(); U(U &&) noexcept = default;}; U u1; U u2 = static_cast<U&&>(u1); — _end example_]

Explicitly-defaulted functions and implicitly-declared functions are collectively called defaulted functions, and the implementation shall provide implicit definitions for them ([class.ctor],[class.dtor], [class.copy.ctor], [class.copy.assign]), including possibly defining them as deleted.

A defaulted prospective destructor ([class.dtor]) that is not a destructor is defined as deleted.

A defaulted special member function that is neither a prospective destructor nor an eligible special member function ([special]) is defined as deleted.

A function isuser-provided if it is user-declared and not explicitly defaulted or deleted on its first declaration.

A user-provided explicitly-defaulted function (i.e., explicitly defaulted after its first declaration) is defined at the point where it is explicitly defaulted; if such a function is implicitly defined as deleted, the program is ill-formed.

[Note 1:

Declaring a function as defaulted after its first declaration can provide efficient execution and concise definition while enabling a stable binary interface to an evolving code base.

— _end note_]

[Example 2: struct trivial { trivial() = default; trivial(const trivial&) = default; trivial(trivial&&) = default; trivial& operator=(const trivial&) = default; trivial& operator=(trivial&&) = default;~trivial() = default;};struct nontrivial1 { nontrivial1();}; nontrivial1::nontrivial1() = default; — _end example_]