- tmp/tmpccph_bb3/{from.md → to.md} +124 -109
tmp/tmpccph_bb3/{from.md → to.md}
RENAMED
|
@@ -50,11 +50,11 @@ Here `int` is the *decl-specifier-seq*; `max(int` `a,` `int` `b,` `int`
|
|
| 50 |
|
| 51 |
A *ctor-initializer* is used only in a constructor; see [[class.ctor]]
|
| 52 |
and [[class.init]].
|
| 53 |
|
| 54 |
[*Note 1*: A *cv-qualifier-seq* affects the type of `this` in the body
|
| 55 |
-
of a member function; see [[
|
| 56 |
|
| 57 |
[*Note 2*:
|
| 58 |
|
| 59 |
Unused parameters need not be named. For example,
|
| 60 |
|
|
@@ -64,13 +64,12 @@ void print(int a, int) {
|
|
| 64 |
}
|
| 65 |
```
|
| 66 |
|
| 67 |
— *end note*]
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
(see [[basic.scope.block]]).
|
| 72 |
|
| 73 |
The function-local predefined variable `__func__` is defined as if a
|
| 74 |
definition of the form
|
| 75 |
|
| 76 |
``` cpp
|
|
@@ -101,47 +100,50 @@ explicitly defaulted shall
|
|
| 101 |
|
| 102 |
- be a special member function or a comparison operator function
|
| 103 |
[[over.binary]], and
|
| 104 |
- not have default arguments.
|
| 105 |
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
implicitly declared, as follows:
|
| 109 |
|
| 110 |
-
- `
|
| 111 |
-
- `
|
| 112 |
-
|
| 113 |
-
parameter of `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
-
If `
|
|
|
|
| 116 |
|
| 117 |
-
- if `F` is an assignment operator, and the return type of `
|
| 118 |
-
from the return type of `
|
| 119 |
-
reference, the program is ill-formed;
|
| 120 |
-
- otherwise, if `F` is explicitly defaulted on its first declaration,
|
| 121 |
-
is defined as deleted;
|
| 122 |
- otherwise, the program is ill-formed.
|
| 123 |
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
on its first declaration is implicitly inline [[dcl.inline]], and is
|
| 128 |
-
implicitly constexpr [[dcl.constexpr]] if it is constexpr-compatible.
|
| 129 |
|
| 130 |
[*Example 1*:
|
| 131 |
|
| 132 |
``` cpp
|
| 133 |
struct S {
|
| 134 |
-
constexpr S() = default; // error: implicit S() is not constexpr
|
| 135 |
S(int a = 0) = default; // error: default argument
|
| 136 |
void operator=(const S&) = default; // error: non-matching return type
|
| 137 |
~S() noexcept(false) = default; // OK, despite mismatched exception specification
|
| 138 |
private:
|
| 139 |
int i;
|
| 140 |
-
S(S&); // OK
|
| 141 |
};
|
| 142 |
-
S::S(S&) = default; // OK
|
| 143 |
|
| 144 |
struct T {
|
| 145 |
T();
|
| 146 |
T(T &&) noexcept(false);
|
| 147 |
};
|
|
@@ -156,21 +158,26 @@ U u2 = static_cast<U&&>(u1); // OK, calls std::terminate if T::T(T&&)
|
|
| 156 |
|
| 157 |
— *end example*]
|
| 158 |
|
| 159 |
Explicitly-defaulted functions and implicitly-declared functions are
|
| 160 |
collectively called *defaulted* functions, and the implementation shall
|
| 161 |
-
provide implicit definitions for them
|
| 162 |
-
[[class.copy.ctor]], [[class.copy.assign]]
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
function (i.e.,
|
| 170 |
-
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
[*Note 1*: Declaring a function as defaulted after its first
|
| 174 |
declaration can provide efficient execution and concise definition while
|
| 175 |
enabling a stable binary interface to an evolving code
|
| 176 |
base. — *end note*]
|
|
@@ -195,24 +202,25 @@ nontrivial1::nontrivial1() = default; // not first declaration
|
|
| 195 |
|
| 196 |
— *end example*]
|
| 197 |
|
| 198 |
### Deleted definitions <a id="dcl.fct.def.delete">[[dcl.fct.def.delete]]</a>
|
| 199 |
|
| 200 |
-
A
|
| 201 |
-
is
|
| 202 |
-
|
|
|
|
|
|
|
| 203 |
|
| 204 |
A program that refers to a deleted function implicitly or explicitly,
|
| 205 |
other than to declare it, is ill-formed.
|
| 206 |
|
| 207 |
[*Note 1*: This includes calling the function implicitly or explicitly
|
| 208 |
and forming a pointer or pointer-to-member to the function. It applies
|
| 209 |
even for references in expressions that are not potentially-evaluated.
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
reference. — *end note*]
|
| 214 |
|
| 215 |
[*Example 1*:
|
| 216 |
|
| 217 |
One can prevent default initialization and initialization by
|
| 218 |
non-`double`s with
|
|
@@ -321,19 +329,21 @@ task<void> g3(int a, ...) { // error: variable parameter list not allowed
|
|
| 321 |
|
| 322 |
— *end example*]
|
| 323 |
|
| 324 |
The *promise type* of a coroutine is
|
| 325 |
`std::coroutine_traits<R, P₁, …, Pₙ>::promise_type`, where `R` is the
|
| 326 |
-
return type of the function, and `P₁` … `Pₙ`
|
| 327 |
-
|
| 328 |
-
parameter [[
|
| 329 |
-
|
| 330 |
|
| 331 |
-
In the following, `pᵢ` is an lvalue of type `Pᵢ`, where `p₁` denotes
|
| 332 |
-
|
| 333 |
-
non-static member function, and `pᵢ` denotes the
|
| 334 |
-
function parameter otherwise.
|
|
|
|
|
|
|
| 335 |
|
| 336 |
A coroutine behaves as if its *function-body* were replaced by:
|
| 337 |
|
| 338 |
``` bnf
|
| 339 |
'{'
|
|
@@ -354,75 +364,81 @@ final-suspend ':'
|
|
| 354 |
```
|
| 355 |
|
| 356 |
where
|
| 357 |
|
| 358 |
- the *await-expression* containing the call to `initial_suspend` is the
|
| 359 |
-
*initial
|
| 360 |
- the *await-expression* containing the call to `final_suspend` is the
|
| 361 |
-
*final
|
| 362 |
- *initial-await-resume-called* is initially `false` and is set to
|
| 363 |
`true` immediately before the evaluation of the *await-resume*
|
| 364 |
-
expression [[expr.await]] of the initial
|
| 365 |
- *promise-type* denotes the promise type, and
|
| 366 |
- the object denoted by the exposition-only name *`promise`* is the
|
| 367 |
*promise object* of the coroutine, and
|
| 368 |
- the label denoted by the name *`final-suspend`* is defined for
|
| 369 |
exposition only [[stmt.return.coroutine]], and
|
| 370 |
- *promise-constructor-arguments* is determined as follows: overload
|
| 371 |
resolution is performed on a promise constructor call created by
|
| 372 |
-
assembling an argument list
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 376 |
|
| 377 |
-
|
| 378 |
-
|
| 379 |
ill-formed.
|
| 380 |
|
| 381 |
-
[*Note 1*: If
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
|
| 386 |
The expression `promise.get_return_object()` is used to initialize the
|
| 387 |
-
|
| 388 |
-
call to `get_return_object` is sequenced before the call to
|
| 389 |
`initial_suspend` and is invoked at most once.
|
| 390 |
|
| 391 |
A suspended coroutine can be resumed to continue execution by invoking a
|
| 392 |
resumption member function [[coroutine.handle.resumption]] of a
|
| 393 |
coroutine handle [[coroutine.handle]] that refers to the coroutine. The
|
| 394 |
-
|
| 395 |
*resumer*. Invoking a resumption member function for a coroutine that is
|
| 396 |
not suspended results in undefined behavior.
|
| 397 |
|
| 398 |
An implementation may need to allocate additional storage for a
|
| 399 |
coroutine. This storage is known as the *coroutine state* and is
|
| 400 |
obtained by calling a non-array allocation function
|
| 401 |
[[basic.stc.dynamic.allocation]]. The allocation function’s name is
|
| 402 |
-
looked up in the scope of the promise type.
|
| 403 |
-
allocation function’s name is looked up in the global scope. If the
|
| 404 |
-
lookup finds an allocation function in the scope of the promise type,
|
| 405 |
-
overload resolution is performed on a function call created by
|
| 406 |
-
assembling an argument list. The first argument is the amount of space
|
| 407 |
-
requested, and has type `std::size_t`. The lvalues `p₁` … `pₙ` are the
|
| 408 |
-
succeeding arguments. If no viable function is found
|
| 409 |
-
[[over.match.viable]], overload resolution is performed again on a
|
| 410 |
-
function call created by passing just the amount of space required as an
|
| 411 |
-
argument of type `std::size_t`.
|
| 412 |
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 424 |
`T::get_return_object_on_allocation_failure()`, where `T` is the promise
|
| 425 |
type.
|
| 426 |
|
| 427 |
[*Example 2*:
|
| 428 |
|
|
@@ -437,11 +453,11 @@ struct generator {
|
|
| 437 |
struct promise_type {
|
| 438 |
int current_value;
|
| 439 |
static auto get_return_object_on_allocation_failure() { return generator{nullptr}; }
|
| 440 |
auto get_return_object() { return generator{handle::from_promise(*this)}; }
|
| 441 |
auto initial_suspend() { return std::suspend_always{}; }
|
| 442 |
-
auto final_suspend() { return std::suspend_always{}; }
|
| 443 |
void unhandled_exception() { std::terminate(); }
|
| 444 |
void return_void() {}
|
| 445 |
auto yield_value(int value) {
|
| 446 |
current_value = value;
|
| 447 |
return std::suspend_always{};
|
|
@@ -467,30 +483,28 @@ int main() {
|
|
| 467 |
|
| 468 |
The coroutine state is destroyed when control flows off the end of the
|
| 469 |
coroutine or the `destroy` member function
|
| 470 |
[[coroutine.handle.resumption]] of a coroutine handle
|
| 471 |
[[coroutine.handle]] that refers to the coroutine is invoked. In the
|
| 472 |
-
latter case
|
| 473 |
-
the
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
has undefined behavior.
|
| 478 |
|
| 479 |
-
The deallocation function’s name is looked up
|
| 480 |
-
promise type. If
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
corresponding argument.
|
| 492 |
|
| 493 |
When a coroutine is invoked, after initializing its parameters
|
| 494 |
[[expr.call]], a copy is created for each coroutine parameter. For a
|
| 495 |
parameter of type cv `T`, the copy is a variable of type cv `T` with
|
| 496 |
automatic storage duration that is direct-initialized from an xvalue of
|
|
@@ -511,10 +525,11 @@ the coroutine after the lifetime of the entity referred to by that
|
|
| 511 |
parameter has ended is likely to result in undefined
|
| 512 |
behavior. — *end note*]
|
| 513 |
|
| 514 |
If the evaluation of the expression `promise.unhandled_exception()`
|
| 515 |
exits via an exception, the coroutine is considered suspended at the
|
| 516 |
-
final suspend point
|
|
|
|
| 517 |
|
| 518 |
The expression `co_await` `promise.final_suspend()` shall not be
|
| 519 |
potentially-throwing [[except.spec]].
|
| 520 |
|
|
|
|
| 50 |
|
| 51 |
A *ctor-initializer* is used only in a constructor; see [[class.ctor]]
|
| 52 |
and [[class.init]].
|
| 53 |
|
| 54 |
[*Note 1*: A *cv-qualifier-seq* affects the type of `this` in the body
|
| 55 |
+
of a member function; see [[expr.prim.this]]. — *end note*]
|
| 56 |
|
| 57 |
[*Note 2*:
|
| 58 |
|
| 59 |
Unused parameters need not be named. For example,
|
| 60 |
|
|
|
|
| 64 |
}
|
| 65 |
```
|
| 66 |
|
| 67 |
— *end note*]
|
| 68 |
|
| 69 |
+
A *function-local predefined variable* is a variable with static storage
|
| 70 |
+
duration that is implicitly defined in a function parameter scope.
|
|
|
|
| 71 |
|
| 72 |
The function-local predefined variable `__func__` is defined as if a
|
| 73 |
definition of the form
|
| 74 |
|
| 75 |
``` cpp
|
|
|
|
| 100 |
|
| 101 |
- be a special member function or a comparison operator function
|
| 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 case the type of
|
| 113 |
+
`F₁` would differ from the type of `F₂` in that the type of `F₁` has
|
| 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
|
| 120 |
+
allowed by the preceding rules, then:
|
| 121 |
|
| 122 |
+
- if `F₁` is an assignment operator, and the return type of `F₁` differs
|
| 123 |
+
from the return type of `F₂` or `F₁`’s non-object parameter type is
|
| 124 |
+
not a reference, the program is ill-formed;
|
| 125 |
+
- otherwise, if `F₁` is explicitly defaulted on its first declaration,
|
| 126 |
+
it is defined as deleted;
|
| 127 |
- otherwise, the program is ill-formed.
|
| 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
|
| 138 |
void operator=(const S&) = default; // error: non-matching return type
|
| 139 |
~S() noexcept(false) = default; // OK, despite mismatched exception specification
|
| 140 |
private:
|
| 141 |
int i;
|
| 142 |
+
S(S&); // OK, private copy constructor
|
| 143 |
};
|
| 144 |
+
S::S(S&) = default; // OK, defines copy constructor
|
| 145 |
|
| 146 |
struct T {
|
| 147 |
T();
|
| 148 |
T(T &&) noexcept(false);
|
| 149 |
};
|
|
|
|
| 158 |
|
| 159 |
— *end example*]
|
| 160 |
|
| 161 |
Explicitly-defaulted functions and implicitly-declared functions are
|
| 162 |
collectively called *defaulted* functions, and the implementation shall
|
| 163 |
+
provide implicit definitions for them
|
| 164 |
+
[[class.ctor]], [[class.dtor]], [[class.copy.ctor]], [[class.copy.assign]]
|
| 165 |
+
as described below, including possibly defining them as deleted. A
|
| 166 |
+
defaulted prospective destructor [[class.dtor]] that is not a destructor
|
| 167 |
+
is defined as deleted. A defaulted special member function that is
|
| 168 |
+
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. A
|
| 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 1*: Declaring a function as defaulted after its first
|
| 181 |
declaration can provide efficient execution and concise definition while
|
| 182 |
enabling a stable binary interface to an evolving code
|
| 183 |
base. — *end note*]
|
|
|
|
| 202 |
|
| 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 of the form `= delete ;` or an explicitly-defaulted
|
| 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 program that refers to a deleted function implicitly or explicitly,
|
| 214 |
other than to declare it, is ill-formed.
|
| 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. — *end note*]
|
|
|
|
| 222 |
|
| 223 |
[*Example 1*:
|
| 224 |
|
| 225 |
One can prevent default initialization and initialization by
|
| 226 |
non-`double`s with
|
|
|
|
| 329 |
|
| 330 |
— *end example*]
|
| 331 |
|
| 332 |
The *promise type* of a coroutine is
|
| 333 |
`std::coroutine_traits<R, P₁, …, Pₙ>::promise_type`, where `R` is the
|
| 334 |
+
return type of the function, and `P₁` … `Pₙ` is the sequence of types of
|
| 335 |
+
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 a non-static member function, and `pᵢ` denotes the iᵗʰ
|
| 342 |
+
function parameter otherwise. For a non-static member function, `q₁` is
|
| 343 |
+
an lvalue that denotes `*this`; any other `qᵢ` is an lvalue that denotes
|
| 344 |
+
the parameter copy corresponding to `pᵢ`, as described below.
|
| 345 |
|
| 346 |
A coroutine behaves as if its *function-body* were replaced by:
|
| 347 |
|
| 348 |
``` bnf
|
| 349 |
'{'
|
|
|
|
| 364 |
```
|
| 365 |
|
| 366 |
where
|
| 367 |
|
| 368 |
- the *await-expression* containing the call to `initial_suspend` is the
|
| 369 |
+
*initial await expression*, and
|
| 370 |
- the *await-expression* containing the call to `final_suspend` is the
|
| 371 |
+
*final await expression*, and
|
| 372 |
- *initial-await-resume-called* is initially `false` and is set to
|
| 373 |
`true` immediately before the evaluation of the *await-resume*
|
| 374 |
+
expression [[expr.await]] of the initial await expression, and
|
| 375 |
- *promise-type* denotes the promise type, and
|
| 376 |
- the object denoted by the exposition-only name *`promise`* is the
|
| 377 |
*promise object* of the coroutine, and
|
| 378 |
- the label denoted by the name *`final-suspend`* is defined for
|
| 379 |
exposition only [[stmt.return.coroutine]], and
|
| 380 |
- *promise-constructor-arguments* is determined as follows: overload
|
| 381 |
resolution is performed on a promise constructor call created by
|
| 382 |
+
assembling an argument list `q₁` … `qₙ`. If a viable constructor is
|
| 383 |
+
found [[over.match.viable]], then *promise-constructor-arguments* is
|
| 384 |
+
`(q₁, …, qₙ)`, otherwise *promise-constructor-arguments* is empty, and
|
| 385 |
+
- a coroutine is suspended at the *initial suspend point* if it is
|
| 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 1*: If `return_void` is found, flowing off the end of a
|
| 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
|
| 401 |
+
returned reference or prvalue result object of a call to a coroutine.
|
| 402 |
+
The call to `get_return_object` is sequenced before the call to
|
| 403 |
`initial_suspend` and is invoked at most once.
|
| 404 |
|
| 405 |
A suspended coroutine can be resumed to continue execution by invoking a
|
| 406 |
resumption member function [[coroutine.handle.resumption]] of a
|
| 407 |
coroutine handle [[coroutine.handle]] that refers to the coroutine. The
|
| 408 |
+
evaluation that invoked a resumption member function is called the
|
| 409 |
*resumer*. Invoking a resumption member function for a coroutine that is
|
| 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]]. The allocation function’s name is
|
| 416 |
+
looked up by searching for it in the scope of the promise type.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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ₙ` are the successive arguments.
|
| 422 |
+
If no viable function is found [[over.match.viable]], overload
|
| 423 |
+
resolution is performed again on a function call created by passing
|
| 424 |
+
just the amount of space required as a prvalue of type `std::size_t`.
|
| 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 |
+
|
| 430 |
+
If a search for the name `get_return_object_on_allocation_failure` in
|
| 431 |
+
the scope of the promise type [[class.member.lookup]] finds any
|
| 432 |
+
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 returns control to the caller of the coroutine and the return
|
| 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 |
|
|
|
|
| 453 |
struct promise_type {
|
| 454 |
int current_value;
|
| 455 |
static auto get_return_object_on_allocation_failure() { return generator{nullptr}; }
|
| 456 |
auto get_return_object() { return generator{handle::from_promise(*this)}; }
|
| 457 |
auto initial_suspend() { return std::suspend_always{}; }
|
| 458 |
+
auto final_suspend() noexcept { return std::suspend_always{}; }
|
| 459 |
void unhandled_exception() { std::terminate(); }
|
| 460 |
void return_void() {}
|
| 461 |
auto yield_value(int value) {
|
| 462 |
current_value = value;
|
| 463 |
return std::suspend_always{};
|
|
|
|
| 483 |
|
| 484 |
The coroutine state is destroyed when control flows off the end of the
|
| 485 |
coroutine or the `destroy` member function
|
| 486 |
[[coroutine.handle.resumption]] of a coroutine handle
|
| 487 |
[[coroutine.handle]] that refers to the coroutine is invoked. In the
|
| 488 |
+
latter case, control in the coroutine is considered to be transferred
|
| 489 |
+
out of the function [[stmt.dcl]]. The storage for the coroutine state is
|
| 490 |
+
released by calling a non-array deallocation function
|
| 491 |
+
[[basic.stc.dynamic.deallocation]]. If `destroy` is called for a
|
| 492 |
+
coroutine that is not suspended, the program has undefined behavior.
|
|
|
|
| 493 |
|
| 494 |
+
The deallocation function’s name is looked up by searching for it in the
|
| 495 |
+
scope of the promise type. If nothing is found, a search is performed in
|
| 496 |
+
the global scope. If both a usual deallocation function with only a
|
| 497 |
+
pointer parameter and a usual deallocation function with both a pointer
|
| 498 |
+
parameter and a size parameter are found, then the selected deallocation
|
| 499 |
+
function shall be the one with two parameters. Otherwise, the selected
|
| 500 |
+
deallocation function shall be the function with one parameter. If no
|
| 501 |
+
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, after initializing its parameters
|
| 508 |
[[expr.call]], a copy is created for each coroutine parameter. For a
|
| 509 |
parameter of type cv `T`, the copy is a variable of type cv `T` with
|
| 510 |
automatic storage duration that is direct-initialized from an xvalue of
|
|
|
|
| 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()`
|
| 529 |
exits via an exception, the coroutine is considered suspended at the
|
| 530 |
+
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 |
|