|
27 | 27 |
|
28 | 28 | \begin{bnf}
|
29 | 29 | \nontermdef{init-declarator}\br
|
30 |
| - declarator initializer\opt |
| 30 | + declarator initializer\opt\br |
| 31 | + declarator requires-clause |
31 | 32 | \end{bnf}
|
32 | 33 |
|
33 | 34 | \pnum
|
|
95 | 96 | \end{codeblock}
|
96 | 97 | \end{note}
|
97 | 98 |
|
| 99 | +\pnum |
| 100 | +The optional \grammarterm{requires-clause} (Clause~\ref{temp}) in an |
| 101 | +\grammarterm{init-declarator} or \grammarterm{member-declarator} |
| 102 | +shall not be present when the declarator does not declare a |
| 103 | +function (\ref{dcl.fct}). |
| 104 | +% |
| 105 | +When present after a declarator, the \grammarterm{requires-clause} |
| 106 | +is called the \defnx{trailing \grammarterm{requires-clause}{}}{% |
| 107 | +trailing requires-clause@trailing \grammarterm{requires-clause}}. |
| 108 | +The trailing \grammarterm{requires-clause} introduces the |
| 109 | +\grammarterm{constraint-expression} that results from interpreting |
| 110 | +its \grammarterm{constraint-logical-or-expression} as a |
| 111 | +\grammarterm{constraint-expression}. |
| 112 | +% |
| 113 | +\begin{example} |
| 114 | +\begin{codeblock} |
| 115 | +void f1(int a) requires true; // OK |
| 116 | +auto f2(int a) -> bool requires true; // OK |
| 117 | +auto f3(int a) requires true -> bool; // error: \grammarterm{requires-clause} precedes \grammarterm{trailing-return-type} |
| 118 | +void (*pf)() requires true; // error: constraint on a variable |
| 119 | +void g(int (*)() requires true); // error: constraint on a \grammarterm{parameter-declaration} |
| 120 | + |
| 121 | +auto* p = new void(*)(char) requires true; // error: not a function declaration |
| 122 | +\end{codeblock} |
| 123 | +\end{example} |
| 124 | + |
98 | 125 | \pnum
|
99 | 126 | Declarators have the syntax
|
100 | 127 |
|
|
1403 | 1430 | \indextext{type!function}%
|
1404 | 1431 | A single name can be used for several different functions in a single scope;
|
1405 | 1432 | this is function overloading (Clause~\ref{over}).
|
1406 |
| -All declarations for a function shall agree exactly |
1407 |
| -in both the return type and the parameter-type-list. |
| 1433 | +All declarations for a function shall have equivalent return types, |
| 1434 | +parameter-type-lists, and \grammarterm{requires-clause}{s} (\ref{temp.over.link}). |
1408 | 1435 | The type of a function is determined using the following rules.
|
1409 | 1436 | The type of each parameter (including function parameter packs) is
|
1410 | 1437 | determined from its own
|
|
1483 | 1510 | The return type, the parameter-type-list, the \grammarterm{ref-qualifier},
|
1484 | 1511 | the \grammarterm{cv-qualifier-seq}, and
|
1485 | 1512 | the exception specification,
|
1486 |
| -but not the default arguments~(\ref{dcl.fct.default}), |
| 1513 | +but not the default arguments~(\ref{dcl.fct.default}) |
| 1514 | +or \grammarterm{requires-clause}{s}~(Clause~\ref{temp}), |
1487 | 1515 | are part of the function type.
|
1488 | 1516 | \begin{note}
|
1489 | 1517 | Function types are checked during the assignments and initializations of
|
|
1990 | 2018 | %
|
1991 | 2019 | \begin{bnf}
|
1992 | 2020 | \nontermdef{function-definition}\br
|
1993 |
| - attribute-specifier-seq\opt decl-specifier-seq\opt declarator virt-specifier-seq\opt function-body |
| 2021 | + attribute-specifier-seq\opt decl-specifier-seq\opt declarator virt-specifier-seq\opt function-body\br |
| 2022 | + attribute-specifier-seq\opt decl-specifier-seq\opt declarator requires-clause function-body |
1994 | 2023 | \end{bnf}
|
1995 | 2024 |
|
1996 | 2025 | \begin{bnf}
|
|
2104 | 2133 | \indextext{definition!function!explicitly-defaulted}%
|
2105 | 2134 |
|
2106 | 2135 | \pnum
|
2107 |
| -A function definition of the form: |
2108 |
| - |
2109 |
| -\begin{ncbnf} |
2110 |
| - attribute-specifier-seq\opt decl-specifier-seq\opt declarator virt-specifier-seq\opt{} \terminal{ = default ;} |
2111 |
| -\end{ncbnf} |
2112 |
| - |
| 2136 | +A function definition |
| 2137 | +with the \grammarterm{function-body} \tcode{= default ;} |
2113 | 2138 | is called an \grammarterm{explicitly-defaulted} definition.
|
2114 | 2139 | A function that is explicitly defaulted shall
|
2115 | 2140 |
|
|
2202 | 2227 | \indextext{definition!function!deleted}%
|
2203 | 2228 |
|
2204 | 2229 | \pnum
|
2205 |
| -A function definition of the form: |
2206 |
| - |
2207 |
| -\begin{ncbnf} |
2208 |
| - attribute-specifier-seq\opt decl-specifier-seq\opt declarator virt-specifier-seq\opt{} \terminal{ = delete ;} |
2209 |
| -\end{ncbnf} |
2210 |
| - |
| 2230 | +A function definition |
| 2231 | +with the \grammarterm{function-body} \tcode{= delete ;} |
2211 | 2232 | is called a \term{deleted definition}. A function with a
|
2212 | 2233 | deleted definition is also called a \term{deleted function}.
|
2213 | 2234 |
|
|
0 commit comments