<html>
<head>
<title>P2107R0: Core Issue 2436: US064 Copy semantics of coroutine parameters</title>

<style type="text/css">
  ins { text-decoration:none; font-weight:bold; background-color:#A0FFA0 }
  del { text-decoration:line-through; background-color:#FFA0A0 }
  strong { font-weight: inherit; color: #2020ff }
  #xins:checked ~ * ins { display:none; visibility:hidden }
  #xdel:checked ~ * del { display:none; visibility:hidden }
</style>

</head>

<body>
ISO/IEC JTC1 SC22 WG21 P2107R0<br/>
Author: Jens Maurer &lt;Jens.Maurer@gmx.net><br/>
Target audience: CWG, Plenary<br/>
2020-02-12<br/>

<h1>P2107R0: Core Issue 2436: US064 Copy semantics of coroutine parameters</h1>

This paper resolves C++17 NB ballot comment US064, also known as core
issue 2436.

<blockquote>
Apply remaining coroutine TS issues to the working paper.
<p>
Proposed change: Apply resolution of the issue 33. “Parameter copy
wording does not capture the intent.” from p0664r8.
</blockquote>

<h2>Wording</h2>

Change in 7.5.4.1 [expr.prim.id.unqual] paragraph 1:

<blockquote>
An identifier is only an id-expression if it has been suitably
declared (Clause 9) or if it appears as part of a declarator-id
(9.3). <ins>An <em>identifier</em> that names a coroutine parameter
refers to the copy of the parameter ([dcl.fct.def.coroutine]).</ins>
[Note: For operator-function-ids, see 12.6; for
conversion-function-ids, see 11.4.7.2; for literal-operator-ids, see
12.6.8; for template-ids, see 13.3. A type-name or decltype-specifier
prefixed by ~ denotes the destructor of the type so named; see
7.5.4.3. Within the definition of a non-static member function, an
identifier that names a non-static member is transformed to a class
member access expression (11.4.2).  — end note]
</blockquote>

Change in 9.4.4  [dcl.fct.def.coroutine] paragraph 13:

<blockquote>
When a coroutine is invoked, <ins>after initializing its parameters
([expr.call]),</ins> a copy is created for each coroutine
parameter. <del>Each such</del> <ins>For a parameter of
type <em>cv</em> <code>T</code>, the</ins> copy is <del>an object</del> <ins>a variable of type <em>cv</em> <code>T</code></ins> with automatic
storage duration that is direct-initialized <del>from an lvalue
referring to the corresponding parameter if the parameter is an lvalue
reference, and</del> from an xvalue <ins>of type <code>T</code></ins>
referring to <del>it otherwise</del> <ins>the parameter</ins>. <ins>[
Note: An original parameter object is never a const or volatile object
(6.8.3 [basic.type.qualifier]). ]</ins> <del>A reference to a
parameter in the function-body of the coroutine and in the call to the
coroutine promise constructor is replaced by a reference to its
copy.</del> The initialization and destruction of each parameter copy
occurs in the context of the called coroutine. Initializations of
parameter copies are sequenced before the call to the coroutine
promise constructor and indeterminately sequenced with respect to each
other. The lifetime of parameter copies ends immediately after the
lifetime of the coroutine promise object ends. [Note: If a coroutine
has a parameter passed by reference, resuming the coroutine after the
lifetime of the entity referred to by that parameter has ended is
likely to result in undefined behavior. — end note]
</blockquote> 

</body>
</html>
