cplusplus / CWG

Core Working Group
23 stars 7 forks source link

CWG2791 [stmt.return],[stmt.return.coroutine] "A function returns to its caller" is unclear #410

Closed Eisenwave closed 8 months ago

Eisenwave commented 1 year ago

Reference: [stmt.return] p1, [stmt.return.coroutine] p1

Issue Description

[stmt.return] p1 states:

A function returns to its caller by the return statement.

[stmt.return] p1 states:

A coroutine returns to its caller or resumer by the co_return statement or when suspended. [...]

These definition borders on saying nothing, because it's unclear what returning means. By comparison, in [dcl.fct.def.coroutine] p10 we see better wording:

[...] the coroutine returns control to the caller of the coroutine [...]

It's also strange to state that co_await returns to the caller inside the definition of co_return. The explanation of co_await's effect on control flow should be self-contained in [expr.await], and not be a quasi-note in another section.

Suggested resolution

Transfer of control is relatively common terminology in the standard. It should be used consistently for return statements, suspensions, etc.

Update [stmt.return] p1:

-A function returns to its caller by the return statement.
+A return statement transfers control to the caller of the function.

Update [stmt.return.coroutine] p1:

-A coroutine returns to its caller or resumer by the co_return statement or when suspended.
+A co_return statement transfers control to the caller or resumer of the coroutine.
 [...]

Update [dcl.fct.def.coroutine] p10:

 [...] the coroutine
-returns
+transfers
control to the caller of the coroutine [...]

Update [expr.await] p1:

 The co_await expression is used to suspend evaluation of a coroutine
 while awaiting completion of the computation represented by the operand expression.
+Suspending the evaluation of a coroutine transfers control to its caller or resumer.
jensmaurer commented 1 year ago

CWG2791