<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 4358: &sect;[exec.as.awaitable] is using "Preconditions:" when it should probably be described in the constraint</title>
<meta property="og:title" content="Issue 4358: &sect;[exec.as.awaitable] is using &quot;Preconditions:&quot; when it should probably be described in the constraint">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue4358.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#New">New</a> status.</em></p>
<h3 id="4358"><a href="lwg-active.html#4358">4358</a>. &sect;[exec.as.awaitable] is using "Preconditions:" when it should probably be described in the constraint</h3>
<p><b>Section:</b> 33.13.1 <a href="https://wg21.link/exec.as.awaitable">[exec.as.awaitable]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
 <b>Submitter:</b> Lewis Baker <b>Opened:</b> 2025-08-27 <b>Last modified:</b> 2025-09-14</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View other</b> <a href="lwg-index-open.html#exec.as.awaitable">active issues</a> in [exec.as.awaitable].</p>
<p><b>View all other</b> <a href="lwg-index.html#exec.as.awaitable">issues</a> in [exec.as.awaitable].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
<p><b>Discussion:</b></p>
<p>
In 33.13.1 <a href="https://wg21.link/exec.as.awaitable">[exec.as.awaitable]</a> bullet 7.2 it states:
</p>
<blockquote>
<ol style="list-style-type: none">
<li><p>(7.2) &mdash; Otherwise, <code>(void(p), expr)</code> if <code><i>is-awaitable</i>&lt;Expr, U&gt;</code> is <code class='backtick'>true</code>, 
where <code class='backtick'>U</code> is an unspecified class type that is not <code class='backtick'>Promise</code> and that lacks a member named <code class='backtick'>await_transform</code>.
<p/>
<i>Preconditions</i>: <code><i>is-awaitable</i>&lt;Expr, Promise&gt;</code> is <code class='backtick'>true</code> and the expression 
<code class='backtick'>co_await expr</code> in a coroutine with promise type <code class='backtick'>U</code> is expression-equivalent to the same expression 
in a coroutine with promise type <code class='backtick'>Promise</code>.</p></li>
</ol>
</blockquote>
<p>
The "<i>Preconditions</i>:" sentence there refers to static properties of the program and so seems like a 
better fit for a <i>Mandates</i>: element or for folding into the constraint.
<p/>
Also, in the part of the precondition above which says "&hellip; and the expression <code class='backtick'>co_await expr</code> in a 
coroutine with promise type <code class='backtick'>U</code> is expression-equivalent to the same expression in a coroutine with promise 
type <code class='backtick'>Promise</code>" it is unclear how this can be satisfied, as the types involved are different and therefore 
the expression cannot be expression-equivalent.
<p/>
I think perhaps what is intended here is something along the lines of the first expression having 
"effects equivalent to" the second expression, instead of "expression-equivalent to"?
<p/>
However, I think there is a more direct way to express the intent here, by instead just requiring that 
<code>decltype(<i>GET-AWAITER</i>(expr))</code> satisfies <code><i>is-awaiter</i>&lt;Promise&gt;</code>.
This checks whether <code class='backtick'>expr</code> would be a valid type to return from a <code class='backtick'>Promise::await_transform()</code> function.
</p>



<p id="res-4358"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/N5014">N5014</a>.
</p>

<ol>

<li><p>Modify 33.13.1 <a href="https://wg21.link/exec.as.awaitable">[exec.as.awaitable]</a> as indicated:</p>

<blockquote>
<p>
-7- <code class='backtick'>as_awaitable</code> is a customization point object. For subexpressions <code class='backtick'>expr</code> and <code class='backtick'>p</code> where <code class='backtick'>p</code> 
is an lvalue, <code class='backtick'>Expr</code> names the type <code class='backtick'>decltype((expr))</code> and <code class='backtick'>Promise</code> names the type 
<code>decay_t&lt;decltype((p))&gt;</code>, <code class='backtick'>as_awaitable(expr, p)</code> is expression-equivalent to, 
except that the evaluations of <code class='backtick'>expr</code> and <code class='backtick'>p</code> are indeterminately sequenced:
</p>
<ol style="list-style-type: none">
<li><p>(7.1) &mdash; <code class='backtick'>expr.as_awaitable(p)</code> if that expression is well-formed.
<p/>
<i>Mandates</i>: <code><i>is-awaitable</i>&lt;A, Promise&gt;</code> is <code class='backtick'>true</code>, where <code class='backtick'>A</code> is the type of 
the expression above.</p></li>
<li><p>(7.2) &mdash; Otherwise, <code>(void(p), expr)</code> if <ins><code>decltype(<i>GET-AWAITER</i>(expr))</code> 
satisfies <code><i>is-awaiter</i>&lt;Promise&gt;</code>.</ins><del><code><i>is-awaitable</i>&lt;Expr, U&gt;</code> is <code class='backtick'>true</code>, 
where <code class='backtick'>U</code> is an unspecified class type that is not <code class='backtick'>Promise</code> and that lacks a member named <code class='backtick'>await_transform</code>.</del>
<p/>
<del><i>Preconditions</i>: <code><i>is-awaitable</i>&lt;Expr, Promise&gt;</code> is <code class='backtick'>true</code> and the expression 
<code class='backtick'>co_await expr</code> in a coroutine with promise type <code class='backtick'>U</code> is expression-equivalent to the same expression 
in a coroutine with promise type <code class='backtick'>Promise</code>.</del></p></li>
<li><p>(7.3) &mdash; [&hellip;]</p></li>
<li><p>(7.4) &mdash; [&hellip;]</p></li>
<li><p>(7.5) &mdash; [&hellip;]</p></li>
</ol>
</blockquote>

</li>

</ol>





</body>
</html>
