[stmt.return.coroutine]

# 8 Statements [[stmt]](./#stmt)

## 8.8 Jump statements [[stmt.jump]](stmt.jump#stmt.return.coroutine)

### 8.8.5 The co_return statement [stmt.return.coroutine]

[coroutine-return-statement:](#nt:coroutine-return-statement "8.8.5 The co_­return statement [stmt.return.coroutine]")  
co_return [*expr-or-braced-init-list*](dcl.init.general#nt:expr-or-braced-init-list "9.5.1 General [dcl.init.general]")opt ;

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/statements.tex#L1165)

A co_return statement transfers control to
the caller or resumer of a coroutine ([[dcl.fct.def.coroutine]](dcl.fct.def.coroutine "9.6.4 Coroutine definitions"))[.](#1.sentence-1)

A coroutine shall not enclose
a return statement ([[stmt.return]](stmt.return "8.8.4 The return statement"))[.](#1.sentence-2)

[*Note [1](#note-1)*:

For this determination, it is irrelevant whether the return statement
is enclosed by a discarded statement ([[stmt.if]](stmt.if "8.5.2 The if statement"))[.](#1.sentence-3)

â *end note*]

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/statements.tex#L1175)

The [*expr-or-braced-init-list*](dcl.init.general#nt:expr-or-braced-init-list "9.5.1 General [dcl.init.general]") of a co_return statement is
called its operand[.](#2.sentence-1)

Let *p* be an lvalue naming the coroutine
promise object ([[dcl.fct.def.coroutine]](dcl.fct.def.coroutine "9.6.4 Coroutine definitions"))[.](#2.sentence-2)

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]](dcl.fct.def.coroutine "9.6.4 Coroutine definitions") and *S* is defined as follows:

- [(2.1)](#2.1)

  If the operand is a [*braced-init-list*](dcl.init.general#nt:braced-init-list "9.5.1 General [dcl.init.general]") or an expression of non-void type,*S* is *p*.return_value([*expr-or-braced-init-list*](dcl.init.general#nt:expr-or-braced-init-list "9.5.1 General [dcl.init.general]"))[.](#2.1.sentence-1)
  The expression *S* shall be a prvalue of type void[.](#2.1.sentence-2)

- [(2.2)](#2.2)

  Otherwise,*S* is the [*compound-statement*](stmt.block#nt:compound-statement "8.4 Compound statement or block [stmt.block]") { [*expression*](expr.comma#nt:expression "7.6.20 Comma operator [expr.comma]")opt ; *p*.return_void(); }[.](#2.2.sentence-1)
  The expression *p*.return_void() shall be a prvalue of type void[.](#2.2.sentence-2)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/statements.tex#L1200)

If a search for the name return_void in the scope of the promise type
finds any declarations,
flowing off the end of a coroutine's [*function-body*](dcl.fct.def.general#nt:function-body "9.6.1 General [dcl.fct.def.general]") is equivalent to a co_return with no operand;
otherwise flowing off the end of a coroutine's [*function-body*](dcl.fct.def.general#nt:function-body "9.6.1 General [dcl.fct.def.general]") results in undefined behavior[.](#3.sentence-1)
