<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3469: Precondition of coroutine_handle::promise may be insufficient</title>
<meta property="og:title" content="Issue 3469: Precondition of coroutine_handle::promise may be insufficient">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3469.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#Resolved">Resolved</a> status.</em></p>
<h3 id="3469"><a href="lwg-defects.html#3469">3469</a>. Precondition of <code>coroutine_handle::promise</code> may be insufficient</h3>
<p><b>Section:</b> 17.13.4.7 <a href="https://wg21.link/coroutine.handle.promise">[coroutine.handle.promise]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Jiang An <b>Opened:</b> 2020-07-25 <b>Last modified:</b> 2020-11-09</p>
<p><b>Priority: </b>2
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>
<p>
The issue is related to LWG <a href="lwg-defects.html#3460" title="Unimplementable noop_coroutine_handle guarantees (Status: C++23)">3460</a><sup><a href="https://cplusplus.github.io/LWG/issue3460" title="Latest snapshot">(i)</a></sup>.
<p/>
Because the <code>coroutine_handle&lt;&gt;</code> base subobject of a <code>coroutine_handle&lt;P1&gt;</code> 
can be assigned from the one of a <code>coroutine_handle&lt;P2&gt;</code>, a <code>coroutine_handle&lt;P1&gt;</code> 
may refer to a coroutine whose promise type is <code>P2</code>. If a <code>coroutine_handle&lt;P&gt;</code> refers 
to a coroutine with difference, a call to <code>promise()</code> should result in undefined behavior IMO.
<p/>
I think that 17.13.4.7 <a href="https://wg21.link/coroutine.handle.promise">[coroutine.handle.promise]</a>/1 should be changed to: "<i>Preconditions:</i> 
<code>*this</code> refers to a coroutine whose promise type is <code>Promise</code>.", and the same precondition 
should be added to 17.13.5.2.5 <a href="https://wg21.link/coroutine.handle.noop.promise">[coroutine.handle.noop.promise]</a>, and hence <code>noexcept</code> should be 
removed from <code>coroutine_handle&lt;noop_coroutine_promise&gt;::promise</code>.
</p>

<p><i>[2020-08-21; Reflector prioritization]</i></p>

<p>
Set priority to 2 after reflector discussions.
</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<p>
This wording is relative to <a href="https://wg21.link/n4861">N4861</a>. 
</p>

<ol>
<li><p>Modify 17.13.4.7 <a href="https://wg21.link/coroutine.handle.promise">[coroutine.handle.promise]</a> as indicated:</p>

<blockquote>
<pre>
Promise&amp; promise() const;
</pre>
<blockquote>
<p>
-1- <i>Preconditions:</i> <code>*this</code> refers to a coroutine <ins>whose promise type is <code>Promise</code></ins>.
<p/>
-2- <i>Returns:</i> A reference to the promise of the coroutine.
</p>
</blockquote>
</blockquote>
</li>

<li><p>Modify 17.13.5.2 <a href="https://wg21.link/coroutine.handle.noop">[coroutine.handle.noop]</a>, class <code>coroutine_handle&lt;noop_coroutine_promise&gt;</code> 
synopsis, as indicated:</p>

<blockquote>
<pre>
[&hellip;]
<i>// 17.13.5.2.5 <a href="https://wg21.link/coroutine.handle.noop.promise">[coroutine.handle.noop.promise]</a>, promise access</i>
noop_coroutine_promise&amp; promise() const <del>noexcept</del>;
[&hellip;]
</pre>
</blockquote>
</li>

<li><p>Modify 17.13.5.2.5 <a href="https://wg21.link/coroutine.handle.noop.promise">[coroutine.handle.noop.promise]</a> as indicated:</p>

<blockquote>
<pre>
noop_coroutine_promise&amp; promise() const <del>noexcept</del>;
</pre>
<blockquote>
<p>
<ins>-?- <i>Preconditions:</i> <code>*this</code> refers to a coroutine whose promise type is <code>noop_coroutine_promise</code>.</ins>
<p/>
-1- <i>Returns:</i> A reference to the promise object associated with this coroutine handle.
</p>
</blockquote>
</blockquote>
</li>
</ol>
</blockquote>
<p><i>[2020-11-09 Resolved by acceptance of <a href="lwg-defects.html#3460" title="Unimplementable noop_coroutine_handle guarantees (Status: C++23)">3460</a><sup><a href="https://cplusplus.github.io/LWG/issue3460" title="Latest snapshot">(i)</a></sup>. Status changed: Tentatively Resolved &rarr; Resolved.]</i></p>



<p id="res-3469"><b>Proposed resolution:</b></p>
<p>This issue is resolved by the resolution of issue <a href="lwg-defects.html#3460" title="Unimplementable noop_coroutine_handle guarantees (Status: C++23)">3460</a><sup><a href="https://cplusplus.github.io/LWG/issue3460" title="Latest snapshot">(i)</a></sup>.</p>





</body>
</html>
