From Jason Turner

[stmt.return.coroutine]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpca_5kdfq/{from.md → to.md} +37 -0
tmp/tmpca_5kdfq/{from.md → to.md} RENAMED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### The `co_return` statement <a id="stmt.return.coroutine">[[stmt.return.coroutine]]</a>
2
+
3
+ ``` bnf
4
+ coroutine-return-statement:
5
+ 'co_return' expr-or-braced-init-listₒₚₜ ';'
6
+ ```
7
+
8
+ A coroutine returns to its caller or resumer [[dcl.fct.def.coroutine]]
9
+ by the `co_return` statement or when suspended [[expr.await]]. A
10
+ coroutine shall not enclose a `return` statement [[stmt.return]].
11
+
12
+ [*Note 1*: For this determination, it is irrelevant whether the
13
+ `return` statement is enclosed by a discarded statement
14
+ [[stmt.if]]. — *end note*]
15
+
16
+ The *expr-or-braced-init-list* of a `co_return` statement is called its
17
+ operand. Let *p* be an lvalue naming the coroutine promise object
18
+ [[dcl.fct.def.coroutine]]. A `co_return` statement is equivalent to:
19
+
20
+ ``` bnf
21
+ '{' S';' 'goto' final-suspend';' '}'
22
+ ```
23
+
24
+ where *`final-suspend`* is the exposition-only label defined in
25
+ [[dcl.fct.def.coroutine]] and *S* is defined as follows:
26
+
27
+ - If the operand is a *braced-init-list* or an expression of non-`void`
28
+ type, *S* is *p*`.return_value(`*expr-or-braced-init-list*`)`. The
29
+ expression *S* shall be a prvalue of type `void`.
30
+ - Otherwise, *S* is the *compound-statement* `{` *expression*ₒₚₜ `;`
31
+ *p*`.return_void()``; }`. The expression *p*`.return_void()` shall be
32
+ a prvalue of type `void`.
33
+
34
+ If *p*`.return_void()` is a valid expression, flowing off the end of a
35
+ coroutine is equivalent to a `co_return` with no operand; otherwise
36
+ flowing off the end of a coroutine results in undefined behavior.
37
+