In cppreference, function declaration, under the section User-provided functions. There is a sentence:
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.
The main question is =default and =delete is a function declaration or a function definition?
Shoudn't that be
Defining a function as defaulted after its first declaration?
The main question is
=defaultand=deleteis a function declaration or a function definition?
As per [dcl.fct.def.delete]/1 and [dcl.fct.def.default]/1 they are definitions. However definitions are also declarations whilst not all declarations are definitions.
Shouldn't that be
Defining a function as defaulted after its first declaration?
As per above both 'declaring' and 'defining' are formally correct, but indeed, using 'defining' could arguably be more non-formally precise.
Finally note that there is key difference between explicitly deleted and explicitly defaulted functions in the context of this question: a deleted function shall be the first declaration of the function (except for deleting explicit specializations of function templates - deletion should be at the first declaration of the specialization), meaning you cannot declare a function and later delete it, say, at its definition local to a translation unit; as per [dcl.fct.def.delete]/4:
A deleted function is implicitly an inline function ([dcl.inline]).
[Note 2: The one-definition rule ([basic.def.odr]) applies to deleted definitions. — end note]
A deleted definition of a function shall be the first declaration of the function or, for an explicit specialization of a function template, the first declaration of that specialization. An implicitly declared allocation or deallocation function ([basic.stc.dynamic]) shall not be defined as deleted.
[Example 4:
struct sometype { sometype(); }; sometype::sometype() = delete; // error: not first declaration— end example]
Those are definitions. But like most (all?) definitions, they're also declarations.
[dcl.fct.def.delete]/1:
A deleted definition of a function is a function definition whose ...
[dcl.fct.def.default]/1:
A function definition whose function-body is of the form
=default;is called an explicitly-defaulted definition ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With