8
Statements
[stmt.stmt]
8.7
Jump statements
[stmt.jump]
8.7.5
The
co_
return
statement
[stmt.return.coroutine]
coroutine-return-statement
:
co_return
expr-or-braced-init-list
o
p
t
;
1
#
A coroutine returns to its caller or resumer (
[dcl.
fct.
def.
coroutine]
) by the
co_
return
statement or when suspended (
[expr.
await]
)
.
A coroutine shall not enclose a
return
statement (
[stmt.
return]
)
.
[
Note
1
:
For this determination, it is irrelevant whether the
return
statement is enclosed by a discarded statement (
[stmt.
if]
)
.
—
end note
]
2
#
The
expr-or-braced-init-list
of a
co_
return
statement is called its operand
.
Let
p
be an lvalue naming the coroutine promise object (
[dcl.
fct.
def.
coroutine]
)
.
A
co_
return
statement is equivalent to:
{
S
;
goto
final-suspend
;
}
where
final-suspend
is the exposition-only label defined in
[dcl.
fct.
def.
coroutine]
and
S
is defined as follows:
(2.1)
If the operand is a
braced-init-list
or an expression of non-
void
type,
S
is
p
.
return_
value
(
expr-or-braced-init-list
)
.
The expression
S
shall be a prvalue of type
void
.
(2.2)
Otherwise,
S
is the
compound-statement
{
expression
o
p
t
;
p
.
return_
void
(
)
;
}
.
The expression
p
.
return_
void
(
)
shall be a prvalue of type
void
.
3
#
If
p
.
return_
void
(
)
is a valid expression, flowing off the end of a coroutine's
function-body
is equivalent to a
co_
return
with no operand; otherwise flowing off the end of a coroutine's
function-body
results in undefined behavior
.