[dcl.fct.def.general]

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

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

### 9.6.1 General [dcl.fct.def.general]

[1](#1)

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

Function definitions have the form

[function-definition:](#nt:function-definition "9.6.1 General [dcl.fct.def.general]")  
[*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]")opt [*decl-specifier-seq*](dcl.spec.general#nt:decl-specifier-seq "9.2.1 General [dcl.spec.general]")opt [*declarator*](dcl.decl.general#nt:declarator "9.3.1 General [dcl.decl.general]") [*virt-specifier-seq*](class.mem.general#nt:virt-specifier-seq "11.4.1 General [class.mem.general]")opt  
 [*function-contract-specifier-seq*](dcl.contract.func#nt:function-contract-specifier-seq "9.4.1 General [dcl.contract.func]")opt [*function-body*](#nt:function-body "9.6.1 General [dcl.fct.def.general]")  
[*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]")opt [*decl-specifier-seq*](dcl.spec.general#nt:decl-specifier-seq "9.2.1 General [dcl.spec.general]")opt [*declarator*](dcl.decl.general#nt:declarator "9.3.1 General [dcl.decl.general]") [*requires-clause*](temp.pre#nt:requires-clause "13.1 Preamble [temp.pre]")  
 [*function-contract-specifier-seq*](dcl.contract.func#nt:function-contract-specifier-seq "9.4.1 General [dcl.contract.func]")opt [*function-body*](#nt:function-body "9.6.1 General [dcl.fct.def.general]")

[function-body:](#nt:function-body "9.6.1 General [dcl.fct.def.general]")  
[*ctor-initializer*](class.base.init#nt:ctor-initializer "11.9.3 Initializing bases and members [class.base.init]")opt [*compound-statement*](stmt.block#nt:compound-statement "8.4 Compound statement or block [stmt.block]")  
[*function-try-block*](except.pre#nt:function-try-block "14.1 Preamble [except.pre]")  
= default ;  
[*deleted-function-body*](#nt:deleted-function-body "9.6.1 General [dcl.fct.def.general]")

[deleted-function-body:](#nt:deleted-function-body "9.6.1 General [dcl.fct.def.general]")  
= delete ;  
= delete ( [*unevaluated-string*](lex.string.uneval#nt:unevaluated-string "5.13.6 Unevaluated strings [lex.string.uneval]") ) ;

Any informal reference to the body of a function should be interpreted as a reference to
the non-terminal [*function-body*](#nt:function-body "9.6.1 General [dcl.fct.def.general]"),
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#nt:mem-initializer-id "11.9.3 Initializing bases and members [class.base.init]") ([[class.base.init]](class.base.init "11.9.3 Initializing bases and members"))[.](#1.sentence-2)

The optional [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]") in a [*function-definition*](#nt:function-definition "9.6.1 General [dcl.fct.def.general]") appertains to the function[.](#1.sentence-3)

A [*function-definition*](#nt:function-definition "9.6.1 General [dcl.fct.def.general]") with a [*virt-specifier-seq*](class.mem.general#nt:virt-specifier-seq "11.4.1 General [class.mem.general]") shall be a [*member-declaration*](class.mem.general#nt:member-declaration "11.4.1 General [class.mem.general]") ([[class.mem]](class.mem "11.4 Class members"))[.](#1.sentence-4)

A [*function-definition*](#nt:function-definition "9.6.1 General [dcl.fct.def.general]") with a [*requires-clause*](temp.pre#nt:requires-clause "13.1 Preamble [temp.pre]") shall define a templated function[.](#1.sentence-5)

[2](#2)

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

In a [*function-definition*](#nt:function-definition "9.6.1 General [dcl.fct.def.general]"),
either void [*declarator*](dcl.decl.general#nt:declarator "9.3.1 General [dcl.decl.general]") ; or [*declarator*](dcl.decl.general#nt:declarator "9.3.1 General [dcl.decl.general]") ; shall be a well-formed function declaration
as described in [[dcl.fct]](dcl.fct "9.3.4.6 Functions")[.](#2.sentence-1)

A function shall be defined only in namespace or class scope[.](#2.sentence-2)

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]](dcl.fct.def.delete "9.6.3 Deleted definitions"))[.](#2.sentence-3)

[3](#3)

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

[*Example [1](#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 the[*decl-specifier-seq*](dcl.spec.general#nt:decl-specifier-seq "9.2.1 General [dcl.spec.general]");max(inta,intb,intc) is the[*declarator*](dcl.decl.general#nt:declarator "9.3.1 General [dcl.decl.general]");{ /* ... */ } is the[*function-body*](#nt:function-body "9.6.1 General [dcl.fct.def.general]")[.](#3.sentence-2)

â *end example*]

[4](#4)

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

A[*ctor-initializer*](class.base.init#nt:ctor-initializer "11.9.3 Initializing bases and members [class.base.init]") is used only in a constructor; see [[class.ctor]](class.ctor "11.4.5 Constructors") and [[class.init]](class.init "11.9 Initialization")[.](#4.sentence-1)

[5](#5)

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

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

A [*cv-qualifier-seq*](dcl.decl.general#nt:cv-qualifier-seq "9.3.1 General [dcl.decl.general]") affects the type of this in the body of a member function; see [[expr.prim.this]](expr.prim.this "7.5.3 This")[.](#5.sentence-1)

â *end note*]

[6](#6)

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

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

Unused parameters need not be named[.](#6.sentence-1)

For example,

void print(int a, int) { std::printf("a = %d\n",a);} â *end note*]

[7](#7)

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

A [*function-local predefined variable*](#def:variable,function-local_predefined "9.6.1 General [dcl.fct.def.general]") is a variable with static
storage duration that is implicitly defined in a function parameter scope[.](#7.sentence-1)

[8](#8)

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

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[.](#8.sentence-1)

It is unspecified whether such a variable has an address
distinct from that of any other object in the program[.](#8.sentence-2)[81](#footnote-81 "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 ([term.odr.use]), its string value need not be present in the program image.")

[*Example [2](#example-2)*: struct S { S() : s(__func__) { } // OKconst char* s;};void f(const char* s = __func__); // error: __func__ is undeclared â *end example*]

[81)](#footnote-81)[81)](#footnoteref-81)

Implementations are
permitted to provide additional predefined variables with names that are reserved to the
implementation ([[lex.name]](lex.name "5.11 Identifiers"))[.](#footnote-81.sentence-1)

If a predefined variable is not
odr-used ([[basic.def.odr]](basic.def.odr#term.odr.use "6.3 One-definition rule")), its string value need not be present in the program image[.](#footnote-81.sentence-2)
