- tmp/tmpud7b8a28/{from.md → to.md} +109 -44
tmp/tmpud7b8a28/{from.md → to.md}
RENAMED
|
@@ -1,30 +1,42 @@
|
|
| 1 |
## Function definitions <a id="dcl.fct.def">[[dcl.fct.def]]</a>
|
| 2 |
|
| 3 |
-
###
|
| 4 |
|
| 5 |
Function definitions have the form
|
| 6 |
|
| 7 |
``` bnf
|
| 8 |
function-definition:
|
| 9 |
-
attribute-specifier-seqₒₚₜ decl-specifier-seqₒₚₜ declarator virt-specifier-seqₒₚₜ
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
```
|
| 12 |
|
| 13 |
``` bnf
|
| 14 |
function-body:
|
| 15 |
ctor-initializerₒₚₜ compound-statement
|
| 16 |
function-try-block
|
| 17 |
'=' default ';'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
'=' delete ';'
|
|
|
|
| 19 |
```
|
| 20 |
|
| 21 |
Any informal reference to the body of a function should be interpreted
|
| 22 |
-
as a reference to the non-terminal *function-body*
|
|
|
|
|
|
|
|
|
|
| 23 |
*attribute-specifier-seq* in a *function-definition* appertains to the
|
| 24 |
-
function. A *virt-specifier-seq*
|
| 25 |
-
|
|
|
|
| 26 |
|
| 27 |
In a *function-definition*, either `void` *declarator* `;` or
|
| 28 |
*declarator* `;` shall be a well-formed function declaration as
|
| 29 |
described in [[dcl.fct]]. A function shall be defined only in namespace
|
| 30 |
or class scope. The type of a parameter or the return type for a
|
|
@@ -96,24 +108,24 @@ void f(const char* s = __func__); // error: __func__ is undeclared
|
|
| 96 |
|
| 97 |
A function definition whose *function-body* is of the form `= default ;`
|
| 98 |
is called an *explicitly-defaulted* definition. A function that is
|
| 99 |
explicitly defaulted shall
|
| 100 |
|
| 101 |
-
- be a special member function or a comparison operator
|
| 102 |
-
[[over.binary]], and
|
| 103 |
-
- not have default arguments.
|
| 104 |
|
| 105 |
An explicitly defaulted special member function `F₁` is allowed to
|
| 106 |
differ from the corresponding special member function `F₂` that would
|
| 107 |
have been implicitly declared, as follows:
|
| 108 |
|
| 109 |
- `F₁` and `F₂` may have differing *ref-qualifier*s;
|
| 110 |
- if `F₂` has an implicit object parameter of type “reference to `C`”,
|
| 111 |
`F₁` may be an explicit object member function whose explicit object
|
| 112 |
-
parameter is of type “reference to `C`”, in which
|
| 113 |
-
`F₁` would differ from the type of `F₂` in that the
|
| 114 |
-
an additional parameter;
|
| 115 |
- `F₁` and `F₂` may have differing exception specifications; and
|
| 116 |
- if `F₂` has a non-object parameter of type `const C&`, the
|
| 117 |
corresponding non-object parameter of `F₁` may be of type `C&`.
|
| 118 |
|
| 119 |
If the type of `F₁` differs from the type of `F₂` in a way other than as
|
|
@@ -128,10 +140,13 @@ allowed by the preceding rules, then:
|
|
| 128 |
|
| 129 |
A function explicitly defaulted on its first declaration is implicitly
|
| 130 |
inline [[dcl.inline]], and is implicitly constexpr [[dcl.constexpr]] if
|
| 131 |
it is constexpr-suitable.
|
| 132 |
|
|
|
|
|
|
|
|
|
|
| 133 |
[*Example 1*:
|
| 134 |
|
| 135 |
``` cpp
|
| 136 |
struct S {
|
| 137 |
S(int a = 0) = default; // error: default argument
|
|
@@ -169,21 +184,25 @@ neither a prospective destructor nor an eligible special member function
|
|
| 169 |
[[special]] is defined as deleted. A function is *user-provided* if it
|
| 170 |
is user-declared and not explicitly defaulted or deleted on its first
|
| 171 |
declaration. A user-provided explicitly-defaulted function (i.e.,
|
| 172 |
explicitly defaulted after its first declaration) is implicitly defined
|
| 173 |
at the point where it is explicitly defaulted; if such a function is
|
| 174 |
-
implicitly defined as deleted, the program is ill-formed.
|
| 175 |
-
non-user-provided defaulted function (i.e., implicitly declared or
|
| 176 |
-
explicitly defaulted in the class) that is not defined as deleted is
|
| 177 |
-
implicitly defined when it is odr-used [[basic.def.odr]] or needed for
|
| 178 |
-
constant evaluation [[expr.const]].
|
| 179 |
|
| 180 |
-
[*Note
|
| 181 |
declaration can provide efficient execution and concise definition while
|
| 182 |
enabling a stable binary interface to an evolving code
|
| 183 |
base. — *end note*]
|
| 184 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
[*Example 2*:
|
| 186 |
|
| 187 |
``` cpp
|
| 188 |
struct trivial {
|
| 189 |
trivial() = default;
|
|
@@ -203,24 +222,30 @@ nontrivial1::nontrivial1() = default; // not first declaration
|
|
| 203 |
— *end example*]
|
| 204 |
|
| 205 |
### Deleted definitions <a id="dcl.fct.def.delete">[[dcl.fct.def.delete]]</a>
|
| 206 |
|
| 207 |
A *deleted definition* of a function is a function definition whose
|
| 208 |
-
*function-body* is
|
| 209 |
definition of the function where the function is defined as deleted. A
|
| 210 |
*deleted function* is a function with a deleted definition or a function
|
| 211 |
that is implicitly defined as deleted.
|
| 212 |
|
| 213 |
-
A
|
| 214 |
-
other than to declare it
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
|
| 216 |
[*Note 1*: This includes calling the function implicitly or explicitly
|
| 217 |
and forming a pointer or pointer-to-member to the function. It applies
|
| 218 |
even for references in expressions that are not potentially-evaluated.
|
| 219 |
For an overload set, only the function selected by overload resolution
|
| 220 |
is referenced. The implicit odr-use [[term.odr.use]] of a virtual
|
| 221 |
-
function does not, by itself, constitute a reference.
|
|
|
|
|
|
|
| 222 |
|
| 223 |
[*Example 1*:
|
| 224 |
|
| 225 |
One can prevent default initialization and initialization by
|
| 226 |
non-`double`s with
|
|
@@ -336,16 +361,20 @@ the non-object function parameters, preceded by the type of the object
|
|
| 336 |
parameter [[dcl.fct]] if the coroutine is a non-static member function.
|
| 337 |
The promise type shall be a class type.
|
| 338 |
|
| 339 |
In the following, `pᵢ` is an lvalue of type `Pᵢ`, where `p₁` denotes the
|
| 340 |
object parameter and `p_i+1` denotes the iᵗʰ non-object function
|
| 341 |
-
parameter for
|
| 342 |
-
function parameter otherwise. For
|
| 343 |
-
an lvalue that denotes `*this`; any other `qᵢ` is an
|
| 344 |
-
the parameter copy corresponding to `pᵢ`, as
|
|
|
|
| 345 |
|
| 346 |
-
A coroutine behaves as if
|
|
|
|
|
|
|
|
|
|
| 347 |
|
| 348 |
``` bnf
|
| 349 |
'{'
|
| 350 |
*promise-type* promise *promise-constructor-arguments* ';'
|
| 351 |
% FIXME: promise'.get_return_object()' ';'
|
|
@@ -386,15 +415,19 @@ where
|
|
| 386 |
suspended at the initial await expression, and
|
| 387 |
- a coroutine is suspended at a *final suspend point* if it is suspended
|
| 388 |
- at a final await expression or
|
| 389 |
- due to an exception exiting from `unhandled_exception()`.
|
| 390 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 391 |
If searches for the names `return_void` and `return_value` in the scope
|
| 392 |
of the promise type each find any declarations, the program is
|
| 393 |
ill-formed.
|
| 394 |
|
| 395 |
-
[*Note
|
| 396 |
coroutine is equivalent to a `co_return` with no operand. Otherwise,
|
| 397 |
flowing off the end of a coroutine results in undefined behavior
|
| 398 |
[[stmt.return.coroutine]]. — *end note*]
|
| 399 |
|
| 400 |
The expression `promise.get_return_object()` is used to initialize the
|
|
@@ -410,20 +443,22 @@ evaluation that invoked a resumption member function is called the
|
|
| 410 |
not suspended results in undefined behavior.
|
| 411 |
|
| 412 |
An implementation may need to allocate additional storage for a
|
| 413 |
coroutine. This storage is known as the *coroutine state* and is
|
| 414 |
obtained by calling a non-array allocation function
|
| 415 |
-
[[basic.stc.dynamic.allocation]]
|
| 416 |
-
looked up by searching for it in the scope
|
|
|
|
| 417 |
|
| 418 |
- If the search finds any declarations, overload resolution is performed
|
| 419 |
on a function call created by assembling an argument list. The first
|
| 420 |
argument is the amount of space requested, and is a prvalue of type
|
| 421 |
-
`std::size_t`. The lvalues `p₁` … `pₙ`
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
|
|
|
| 425 |
- If the search finds no declarations, a search is performed in the
|
| 426 |
global scope. Overload resolution is performed on a function call
|
| 427 |
created by passing the amount of space required as a prvalue of type
|
| 428 |
`std::size_t`.
|
| 429 |
|
|
@@ -433,12 +468,12 @@ declarations, then the result of a call to an allocation function used
|
|
| 433 |
to obtain storage for the coroutine state is assumed to return `nullptr`
|
| 434 |
if it fails to obtain storage, and if a global allocation function is
|
| 435 |
selected, the `::operator new(size_t, nothrow_t)` form is used. The
|
| 436 |
allocation function used in this case shall have a non-throwing
|
| 437 |
*noexcept-specifier*. If the allocation function returns `nullptr`, the
|
| 438 |
-
coroutine
|
| 439 |
-
value is obtained by a call to
|
| 440 |
`T::get_return_object_on_allocation_failure()`, where `T` is the promise
|
| 441 |
type.
|
| 442 |
|
| 443 |
[*Example 2*:
|
| 444 |
|
|
@@ -502,27 +537,32 @@ usual deallocation function is found, the program is ill-formed. The
|
|
| 502 |
selected deallocation function shall be called with the address of the
|
| 503 |
block of storage to be reclaimed as its first argument. If a
|
| 504 |
deallocation function with a parameter of type `std::size_t` is used,
|
| 505 |
the size of the block is passed as the corresponding argument.
|
| 506 |
|
| 507 |
-
When a coroutine is invoked,
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
automatic storage duration that is direct-initialized from an xvalue of
|
| 511 |
-
type `T` referring to the parameter.
|
| 512 |
|
| 513 |
-
|
| 514 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 515 |
|
| 516 |
The initialization and destruction of each parameter copy occurs in the
|
| 517 |
context of the called coroutine. Initializations of parameter copies are
|
| 518 |
sequenced before the call to the coroutine promise constructor and
|
| 519 |
indeterminately sequenced with respect to each other. The lifetime of
|
| 520 |
parameter copies ends immediately after the lifetime of the coroutine
|
| 521 |
promise object ends.
|
| 522 |
|
| 523 |
-
[*Note
|
| 524 |
the coroutine after the lifetime of the entity referred to by that
|
| 525 |
parameter has ended is likely to result in undefined
|
| 526 |
behavior. — *end note*]
|
| 527 |
|
| 528 |
If the evaluation of the expression `promise.unhandled_exception()`
|
|
@@ -531,5 +571,30 @@ final suspend point and the exception propagates to the caller or
|
|
| 531 |
resumer.
|
| 532 |
|
| 533 |
The expression `co_await` `promise.final_suspend()` shall not be
|
| 534 |
potentially-throwing [[except.spec]].
|
| 535 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
## Function definitions <a id="dcl.fct.def">[[dcl.fct.def]]</a>
|
| 2 |
|
| 3 |
+
### General <a id="dcl.fct.def.general">[[dcl.fct.def.general]]</a>
|
| 4 |
|
| 5 |
Function definitions have the form
|
| 6 |
|
| 7 |
``` bnf
|
| 8 |
function-definition:
|
| 9 |
+
attribute-specifier-seqₒₚₜ decl-specifier-seqₒₚₜ declarator virt-specifier-seqₒₚₜ
|
| 10 |
+
function-contract-specifier-seqₒₚₜ function-body
|
| 11 |
+
attribute-specifier-seqₒₚₜ decl-specifier-seqₒₚₜ declarator requires-clause
|
| 12 |
+
function-contract-specifier-seqₒₚₜ function-body
|
| 13 |
```
|
| 14 |
|
| 15 |
``` bnf
|
| 16 |
function-body:
|
| 17 |
ctor-initializerₒₚₜ compound-statement
|
| 18 |
function-try-block
|
| 19 |
'=' default ';'
|
| 20 |
+
deleted-function-body
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
``` bnf
|
| 24 |
+
deleted-function-body:
|
| 25 |
'=' delete ';'
|
| 26 |
+
'=' delete '(' unevaluated-string ')' ';'
|
| 27 |
```
|
| 28 |
|
| 29 |
Any informal reference to the body of a function should be interpreted
|
| 30 |
+
as a reference to the non-terminal *function-body*, including, for a
|
| 31 |
+
constructor, default member initializers or default initialization used
|
| 32 |
+
to initialize a base or member subobject in the absence of a
|
| 33 |
+
*mem-initializer-id* [[class.base.init]]. The optional
|
| 34 |
*attribute-specifier-seq* in a *function-definition* appertains to the
|
| 35 |
+
function. A *function-definition* with a *virt-specifier-seq* shall be a
|
| 36 |
+
*member-declaration* [[class.mem]]. A *function-definition* with a
|
| 37 |
+
*requires-clause* shall define a templated function.
|
| 38 |
|
| 39 |
In a *function-definition*, either `void` *declarator* `;` or
|
| 40 |
*declarator* `;` shall be a well-formed function declaration as
|
| 41 |
described in [[dcl.fct]]. A function shall be defined only in namespace
|
| 42 |
or class scope. The type of a parameter or the return type for a
|
|
|
|
| 108 |
|
| 109 |
A function definition whose *function-body* is of the form `= default ;`
|
| 110 |
is called an *explicitly-defaulted* definition. A function that is
|
| 111 |
explicitly defaulted shall
|
| 112 |
|
| 113 |
+
- be a special member function [[special]] or a comparison operator
|
| 114 |
+
function [[over.binary]], [[class.compare.default]], and
|
| 115 |
+
- not have default arguments [[dcl.fct.default]].
|
| 116 |
|
| 117 |
An explicitly defaulted special member function `F₁` is allowed to
|
| 118 |
differ from the corresponding special member function `F₂` that would
|
| 119 |
have been implicitly declared, as follows:
|
| 120 |
|
| 121 |
- `F₁` and `F₂` may have differing *ref-qualifier*s;
|
| 122 |
- if `F₂` has an implicit object parameter of type “reference to `C`”,
|
| 123 |
`F₁` may be an explicit object member function whose explicit object
|
| 124 |
+
parameter is of (possibly different) type “reference to `C`”, in which
|
| 125 |
+
case the type of `F₁` would differ from the type of `F₂` in that the
|
| 126 |
+
type of `F₁` has an additional parameter;
|
| 127 |
- `F₁` and `F₂` may have differing exception specifications; and
|
| 128 |
- if `F₂` has a non-object parameter of type `const C&`, the
|
| 129 |
corresponding non-object parameter of `F₁` may be of type `C&`.
|
| 130 |
|
| 131 |
If the type of `F₁` differs from the type of `F₂` in a way other than as
|
|
|
|
| 140 |
|
| 141 |
A function explicitly defaulted on its first declaration is implicitly
|
| 142 |
inline [[dcl.inline]], and is implicitly constexpr [[dcl.constexpr]] if
|
| 143 |
it is constexpr-suitable.
|
| 144 |
|
| 145 |
+
[*Note 1*: Other defaulted functions are not implicitly
|
| 146 |
+
constexpr. — *end note*]
|
| 147 |
+
|
| 148 |
[*Example 1*:
|
| 149 |
|
| 150 |
``` cpp
|
| 151 |
struct S {
|
| 152 |
S(int a = 0) = default; // error: default argument
|
|
|
|
| 184 |
[[special]] is defined as deleted. A function is *user-provided* if it
|
| 185 |
is user-declared and not explicitly defaulted or deleted on its first
|
| 186 |
declaration. A user-provided explicitly-defaulted function (i.e.,
|
| 187 |
explicitly defaulted after its first declaration) is implicitly defined
|
| 188 |
at the point where it is explicitly defaulted; if such a function is
|
| 189 |
+
implicitly defined as deleted, the program is ill-formed.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
|
| 191 |
+
[*Note 2*: Declaring a function as defaulted after its first
|
| 192 |
declaration can provide efficient execution and concise definition while
|
| 193 |
enabling a stable binary interface to an evolving code
|
| 194 |
base. — *end note*]
|
| 195 |
|
| 196 |
+
A non-user-provided defaulted function (i.e., implicitly declared or
|
| 197 |
+
explicitly defaulted in the class) that is not defined as deleted is
|
| 198 |
+
implicitly defined when it is odr-used [[basic.def.odr]] or needed for
|
| 199 |
+
constant evaluation [[expr.const]].
|
| 200 |
+
|
| 201 |
+
[*Note 3*: The implicit definition of a non-user-provided defaulted
|
| 202 |
+
function does not bind any names. — *end note*]
|
| 203 |
+
|
| 204 |
[*Example 2*:
|
| 205 |
|
| 206 |
``` cpp
|
| 207 |
struct trivial {
|
| 208 |
trivial() = default;
|
|
|
|
| 222 |
— *end example*]
|
| 223 |
|
| 224 |
### Deleted definitions <a id="dcl.fct.def.delete">[[dcl.fct.def.delete]]</a>
|
| 225 |
|
| 226 |
A *deleted definition* of a function is a function definition whose
|
| 227 |
+
*function-body* is a *deleted-function-body* or an explicitly-defaulted
|
| 228 |
definition of the function where the function is defined as deleted. A
|
| 229 |
*deleted function* is a function with a deleted definition or a function
|
| 230 |
that is implicitly defined as deleted.
|
| 231 |
|
| 232 |
+
A construct that designates a deleted function implicitly or explicitly,
|
| 233 |
+
other than to declare it or to appear as the operand of a
|
| 234 |
+
*reflect-expression* [[expr.reflect]], is ill-formed.
|
| 235 |
+
|
| 236 |
+
*Recommended practice:* The resulting diagnostic message should include
|
| 237 |
+
the text of the *unevaluated-string*, if one is supplied.
|
| 238 |
|
| 239 |
[*Note 1*: This includes calling the function implicitly or explicitly
|
| 240 |
and forming a pointer or pointer-to-member to the function. It applies
|
| 241 |
even for references in expressions that are not potentially-evaluated.
|
| 242 |
For an overload set, only the function selected by overload resolution
|
| 243 |
is referenced. The implicit odr-use [[term.odr.use]] of a virtual
|
| 244 |
+
function does not, by itself, constitute a reference. The
|
| 245 |
+
*unevaluated-string*, if present, can be used to explain the rationale
|
| 246 |
+
for deletion and/or to suggest an alternative. — *end note*]
|
| 247 |
|
| 248 |
[*Example 1*:
|
| 249 |
|
| 250 |
One can prevent default initialization and initialization by
|
| 251 |
non-`double`s with
|
|
|
|
| 361 |
parameter [[dcl.fct]] if the coroutine is a non-static member function.
|
| 362 |
The promise type shall be a class type.
|
| 363 |
|
| 364 |
In the following, `pᵢ` is an lvalue of type `Pᵢ`, where `p₁` denotes the
|
| 365 |
object parameter and `p_i+1` denotes the iᵗʰ non-object function
|
| 366 |
+
parameter for an implicit object member function, and `pᵢ` denotes the
|
| 367 |
+
iᵗʰ function parameter otherwise. For an implicit object member
|
| 368 |
+
function, `q₁` is an lvalue that denotes `*this`; any other `qᵢ` is an
|
| 369 |
+
lvalue that denotes the parameter copy corresponding to `pᵢ`, as
|
| 370 |
+
described below.
|
| 371 |
|
| 372 |
+
A coroutine behaves as if the top-level cv-qualifiers in all
|
| 373 |
+
*parameter-declaration*s in the declarator of its *function-definition*
|
| 374 |
+
were removed and its *function-body* were replaced by the following
|
| 375 |
+
*replacement body*:
|
| 376 |
|
| 377 |
``` bnf
|
| 378 |
'{'
|
| 379 |
*promise-type* promise *promise-constructor-arguments* ';'
|
| 380 |
% FIXME: promise'.get_return_object()' ';'
|
|
|
|
| 415 |
suspended at the initial await expression, and
|
| 416 |
- a coroutine is suspended at a *final suspend point* if it is suspended
|
| 417 |
- at a final await expression or
|
| 418 |
- due to an exception exiting from `unhandled_exception()`.
|
| 419 |
|
| 420 |
+
[*Note 1*: An odr-use of a non-reference parameter in a postcondition
|
| 421 |
+
assertion of a coroutine is ill-formed
|
| 422 |
+
[[dcl.contract.func]]. — *end note*]
|
| 423 |
+
|
| 424 |
If searches for the names `return_void` and `return_value` in the scope
|
| 425 |
of the promise type each find any declarations, the program is
|
| 426 |
ill-formed.
|
| 427 |
|
| 428 |
+
[*Note 2*: If `return_void` is found, flowing off the end of a
|
| 429 |
coroutine is equivalent to a `co_return` with no operand. Otherwise,
|
| 430 |
flowing off the end of a coroutine results in undefined behavior
|
| 431 |
[[stmt.return.coroutine]]. — *end note*]
|
| 432 |
|
| 433 |
The expression `promise.get_return_object()` is used to initialize the
|
|
|
|
| 443 |
not suspended results in undefined behavior.
|
| 444 |
|
| 445 |
An implementation may need to allocate additional storage for a
|
| 446 |
coroutine. This storage is known as the *coroutine state* and is
|
| 447 |
obtained by calling a non-array allocation function
|
| 448 |
+
[[basic.stc.dynamic.allocation]] as part of the replacement body. The
|
| 449 |
+
allocation function’s name is looked up by searching for it in the scope
|
| 450 |
+
of the promise type.
|
| 451 |
|
| 452 |
- If the search finds any declarations, overload resolution is performed
|
| 453 |
on a function call created by assembling an argument list. The first
|
| 454 |
argument is the amount of space requested, and is a prvalue of type
|
| 455 |
+
`std::size_t`. The lvalues `p₁` … `pₙ` with their original types
|
| 456 |
+
(including cv-qualifiers) are the successive arguments. If no viable
|
| 457 |
+
function is found [[over.match.viable]], overload resolution is
|
| 458 |
+
performed again on a function call created by passing just the amount
|
| 459 |
+
of space required as a prvalue of type `std::size_t`.
|
| 460 |
- If the search finds no declarations, a search is performed in the
|
| 461 |
global scope. Overload resolution is performed on a function call
|
| 462 |
created by passing the amount of space required as a prvalue of type
|
| 463 |
`std::size_t`.
|
| 464 |
|
|
|
|
| 468 |
to obtain storage for the coroutine state is assumed to return `nullptr`
|
| 469 |
if it fails to obtain storage, and if a global allocation function is
|
| 470 |
selected, the `::operator new(size_t, nothrow_t)` form is used. The
|
| 471 |
allocation function used in this case shall have a non-throwing
|
| 472 |
*noexcept-specifier*. If the allocation function returns `nullptr`, the
|
| 473 |
+
coroutine transfers control to the caller of the coroutine and the
|
| 474 |
+
return value is obtained by a call to
|
| 475 |
`T::get_return_object_on_allocation_failure()`, where `T` is the promise
|
| 476 |
type.
|
| 477 |
|
| 478 |
[*Example 2*:
|
| 479 |
|
|
|
|
| 537 |
selected deallocation function shall be called with the address of the
|
| 538 |
block of storage to be reclaimed as its first argument. If a
|
| 539 |
deallocation function with a parameter of type `std::size_t` is used,
|
| 540 |
the size of the block is passed as the corresponding argument.
|
| 541 |
|
| 542 |
+
When a coroutine is invoked, a copy is created for each coroutine
|
| 543 |
+
parameter at the beginning of the replacement body. For a parameter
|
| 544 |
+
whose original declaration specified the type cv `T`,
|
|
|
|
|
|
|
| 545 |
|
| 546 |
+
- if `T` is a reference type, the copy is a reference of type cv `T`
|
| 547 |
+
bound to the same object as a parameter;
|
| 548 |
+
- otherwise, the copy is a variable of type cv `T` with automatic
|
| 549 |
+
storage duration that is direct-initialized from an xvalue of type `T`
|
| 550 |
+
referring to the parameter.
|
| 551 |
+
|
| 552 |
+
[*Note 3*: An identifier in the *function-body* that names one of these
|
| 553 |
+
parameters refers to the created copy, not the original parameter
|
| 554 |
+
[[expr.prim.id.unqual]]. — *end note*]
|
| 555 |
|
| 556 |
The initialization and destruction of each parameter copy occurs in the
|
| 557 |
context of the called coroutine. Initializations of parameter copies are
|
| 558 |
sequenced before the call to the coroutine promise constructor and
|
| 559 |
indeterminately sequenced with respect to each other. The lifetime of
|
| 560 |
parameter copies ends immediately after the lifetime of the coroutine
|
| 561 |
promise object ends.
|
| 562 |
|
| 563 |
+
[*Note 4*: If a coroutine has a parameter passed by reference, resuming
|
| 564 |
the coroutine after the lifetime of the entity referred to by that
|
| 565 |
parameter has ended is likely to result in undefined
|
| 566 |
behavior. — *end note*]
|
| 567 |
|
| 568 |
If the evaluation of the expression `promise.unhandled_exception()`
|
|
|
|
| 571 |
resumer.
|
| 572 |
|
| 573 |
The expression `co_await` `promise.final_suspend()` shall not be
|
| 574 |
potentially-throwing [[except.spec]].
|
| 575 |
|
| 576 |
+
### Replaceable function definitions <a id="dcl.fct.def.replace">[[dcl.fct.def.replace]]</a>
|
| 577 |
+
|
| 578 |
+
Certain functions for which a definition is supplied by the
|
| 579 |
+
implementation are *replaceable*. A C++ program may provide a definition
|
| 580 |
+
with the signature of a replaceable function, called a
|
| 581 |
+
*replacement function*. The replacement function is used instead of the
|
| 582 |
+
default version supplied by the implementation. Such replacement occurs
|
| 583 |
+
prior to program startup [[basic.def.odr]], [[basic.start]]. A
|
| 584 |
+
declaration of the replacement function
|
| 585 |
+
|
| 586 |
+
- shall not be inline,
|
| 587 |
+
- shall be attached to the global module,
|
| 588 |
+
- shall have C++ language linkage,
|
| 589 |
+
- shall have the same return type as the replaceable function, and
|
| 590 |
+
- if the function is declared in a standard library header, shall be
|
| 591 |
+
such that it would be valid as a redeclaration of the declaration in
|
| 592 |
+
that header;
|
| 593 |
+
|
| 594 |
+
no diagnostic is required.
|
| 595 |
+
|
| 596 |
+
[*Note 1*: The one-definition rule [[basic.def.odr]] applies to the
|
| 597 |
+
definitions of a replaceable function provided by the program. The
|
| 598 |
+
implementation-supplied function definition is an otherwise-unnamed
|
| 599 |
+
function with no linkage. — *end note*]
|
| 600 |
+
|