[dcl.fct.def.default]

# 9 Declarations [[dcl]](./#dcl)

## 9.6 Function definitions [[dcl.fct.def]](dcl.fct.def#default)

### 9.6.2 Explicitly-defaulted functions [dcl.fct.def.default]

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L6967)

A function definition whose[*function-body*](dcl.fct.def.general#nt:function-body "9.6.1 General [dcl.fct.def.general]") is of the form= default ; is called an [*explicitly-defaulted*](#def:definition,function,explicitly-defaulted "9.6.2 Explicitly-defaulted functions [dcl.fct.def.default]") definition[.](#1.sentence-1)

A function that is explicitly defaulted shall

- [(1.1)](#1.1)

be a special member function ([[special]](special "11.4.4 Special member functions")) or
a comparison operator function ([[over.binary]](over.binary "12.4.3 Binary operators"), [[class.compare.default]](class.compare.default "11.10.1 Defaulted comparison operator functions")), and

- [(1.2)](#1.2)

not have default arguments ([[dcl.fct.default]](dcl.fct.default "9.3.4.7 Default arguments"))[.](#1.sentence-2)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L6980)

An explicitly defaulted special member function F1 is allowed to differ from
the corresponding special member function F2 that would have been implicitly declared, as follows:

- [(2.1)](#2.1)

F1 and F2 may have differing [*ref-qualifier*](dcl.decl.general#nt:ref-qualifier "9.3.1 General [dcl.decl.general]")*s*;

- [(2.2)](#2.2)

if F2 has an implicit object parameter of
 type âreference to Câ, F1 may be an explicit object member function whose
 explicit object parameter is of (possibly different) type âreference to Câ,
 in which case the type of F1 would differ from the type of F2 in that the type of F1 has an additional parameter;

- [(2.3)](#2.3)

F1 and F2 may have differing exception specifications; and

- [(2.4)](#2.4)

if F2 has a non-object parameter of type const C&,
 the corresponding non-object parameter of F1 may be of
 type C&[.](#2.sentence-1)

If the type of F1 differs from the type of F2 in a way
other than as allowed by the preceding rules, then:

- [(2.5)](#2.5)

if F1 is an assignment operator, and
 the return type of F1 differs from
 the return type of F2 or F1's non-object parameter type is not a reference,
 the program is ill-formed;

- [(2.6)](#2.6)

otherwise, if F1 is explicitly defaulted on its first declaration,
 it is defined as deleted;

- [(2.7)](#2.7)

otherwise, the program is ill-formed[.](#2.sentence-2)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L7018)

A function explicitly defaulted on its first declaration
is implicitly inline ([[dcl.inline]](dcl.inline "9.2.8 The inline specifier")),
and is implicitly constexpr ([[dcl.constexpr]](dcl.constexpr "9.2.6 The constexpr and consteval specifiers"))
if it is constexpr-suitable[.](#3.sentence-1)

[*Note [1](#note-1)*:

Other defaulted functions are not implicitly constexpr[.](#3.sentence-2)

â *end note*]

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L7027)

[*Example [1](#example-1)*: struct S { S(int a = 0) = default; // error: default argumentvoid operator=(const S&) = default; // error: non-matching return type~S() noexcept(false) = default; // OK, despite mismatched exception specificationprivate:int i;
 S(S&); // OK, private copy constructor};
S::S(S&) = default; // OK, defines copy constructorstruct T { T();
 T(T &&) noexcept(false);};struct U { T t;
 U();
 U(U &&) noexcept = default;};
U u1;
U u2 = static_cast<U&&>(u1); // OK, calls std​::​terminate if T​::​T(T&&) throws â *end example*]

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L7054)

Explicitly-defaulted functions and implicitly-declared functions are collectively
called [*defaulted*](#def:defaulted "9.6.2 Explicitly-defaulted functions [dcl.fct.def.default]") functions, and the implementation
shall provide implicit definitions
for them ([[class.ctor]](class.ctor "11.4.5 Constructors"), [[class.dtor]](class.dtor "11.4.7 Destructors"), [[class.copy.ctor]](class.copy.ctor "11.4.5.3 Copy/move constructors"), [[class.copy.assign]](class.copy.assign "11.4.6 Copy/move assignment operator")) as described below,
including possibly defining them as deleted[.](#5.sentence-1)

A defaulted prospective destructor ([[class.dtor]](class.dtor "11.4.7 Destructors"))
that is not a destructor is defined as deleted[.](#5.sentence-2)

A defaulted special member function
that is neither a prospective destructor nor
an eligible special member function ([[special]](special "11.4.4 Special member functions"))
is defined as deleted[.](#5.sentence-3)

A function is[*user-provided*](#def:user-provided "9.6.2 Explicitly-defaulted functions [dcl.fct.def.default]") if it is user-declared and not explicitly
defaulted or deleted on its first declaration[.](#5.sentence-4)

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

[*Note [2](#note-2)*:

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[.](#5.sentence-6)

â *end note*]

A non-user-provided defaulted function
(i.e., implicitly declared or explicitly defaulted in the class)
that is not defined as deleted is implicitly defined when it is odr-used ([[basic.def.odr]](basic.def.odr "6.3 One-definition rule"))
or needed for constant evaluation ([[expr.const]](expr.const "7.7 Constant expressions"))[.](#5.sentence-7)

[*Note [3](#note-3)*:

The implicit definition of a non-user-provided defaulted function
does not bind any names[.](#5.sentence-8)

â *end note*]

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L7086)

[*Example [2](#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; // not first declaration â *end example*]
