8.1 KiB
[dcl.fct.def.general]
9 Declarations [dcl]
9.6 Function definitions [dcl.fct.def]
9.6.1 General [dcl.fct.def.general]
Function definitions have the form
function-definition:
attribute-specifier-seqopt decl-specifier-seqopt declarator virt-specifier-seqopt
function-contract-specifier-seqopt function-body
attribute-specifier-seqopt decl-specifier-seqopt declarator requires-clause
function-contract-specifier-seqopt function-body
function-body:
ctor-initializeropt compound-statement
function-try-block
= default ;
deleted-function-body
deleted-function-body:
= delete ;
= delete ( unevaluated-string ) ;
Any informal reference to the body of a function should be interpreted as a reference to the non-terminal function-body, including, for a constructor, default member initializers or default initialization used to initialize a base or member subobject in the absence of a mem-initializer-id ([class.base.init]).
The optional attribute-specifier-seq in a function-definition appertains to the function.
A function-definition with a virt-specifier-seq shall be a member-declaration ([class.mem]).
A function-definition with a requires-clause shall define a templated function.
In a function-definition, either void declarator ; or declarator ; shall be a well-formed function declaration as described in [dcl.fct].
A function shall be defined only in namespace or class scope.
The type of a parameter or the return type for a function definition shall not be a (possibly cv-qualified) class type that is incomplete or abstract within the function body unless the function is deleted ([dcl.fct.def.delete]).
[Example 1:
A simple example of a complete function definition isint max(int a, int b, int c) {int m = (a > b) ? a : b; return (m > c) ? m : c;}
Hereint is thedecl-specifier-seq;max(inta,intb,intc) is thedeclarator;{ /* ... */ } is thefunction-body.
â end example]
Actor-initializer is used only in a constructor; see [class.ctor] and [class.init].
[Note 1:
A cv-qualifier-seq affects the type of this in the body of a member function; see [expr.prim.this].
â end note]
[Note 2:
Unused parameters need not be named.
For example,
void print(int a, int) { std::printf("a = %d\n",a);} â end note]
A function-local predefined variable is a variable with static storage duration that is implicitly defined in a function parameter scope.
The function-local predefined variable func is defined as if a definition of the formstatic const char func[] = "function-name"; had been provided, where function-name is an implementation-defined string.
It is unspecified whether such a variable has an address distinct from that of any other object in the program.81
[Example 2: struct S { S() : s(func) { } // OKconst char* s;};void f(const char* s = func); // error: func is undeclared â end example]
Implementations are permitted to provide additional predefined variables with names that are reserved to the implementation ([lex.name]).
If a predefined variable is not odr-used ([basic.def.odr]), its string value need not be present in the program image.