<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2697: [concurr.ts] Behavior of future/shared_future unwrapping constructor when given an invalid future</title>
<meta property="og:title" content="Issue 2697: [concurr.ts] Behavior of future/shared_future unwrapping constructor when given an invalid future">
<meta property="og:description" content="C++ library issue. Status: C++23">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2697.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#C++23">C++23</a> status.</em></p>
<h3 id="2697"><a href="lwg-defects.html#2697">2697</a>. [concurr.ts] Behavior of <code>future/shared_future</code> unwrapping constructor when given an invalid <code>future</code></h3>
<p><b>Section:</b> 99 [concurr.ts::futures.unique_future], 99 [concurr.ts::futures.shared_future] <b>Status:</b> <a href="lwg-active.html#C++23">C++23</a>
 <b>Submitter:</b> Tim Song <b>Opened:</b> 2016-04-22 <b>Last modified:</b> 2023-11-22</p>
<p><b>Priority: </b>2
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++23">C++23</a> status.</p>
<p><b>Discussion:</b></p>
<p><b>Addresses: concurr.ts</b></p>

<p>
In the concurrency TS, the future/shared_future unwrapping constructors
</p>
<blockquote><pre>
future(future&lt;future&lt;R&gt;&gt;&amp;&amp;) noexcept;
shared_future(future&lt;shared_future&lt;R&gt;&gt;&amp;&amp; rhs) noexcept;
</pre></blockquote>
<p>
appear to implicitly require <code>rhs</code> be valid (e.g., by referring to its shared state, and by requiring a 
<code>valid() == true</code> postcondition). However, they are also marked <code>noexcept</code>, suggesting that they 
are wide-contract, and also makes the usual suggested handling for invalid futures, throwing a 
<code>future_error</code>, impossible.
<p/>
Either the <code>noexcept</code> should be removed, or the behavior with an invalid future should be specified.
</p>

<p>
<strong>Original resolution alternative #1 [NOT CHOSEN]:</strong>
</p>
<blockquote class="note">
<p>
This wording is relative to <a href="https://wg21.link/n4577">N4577</a>.
</p>

<p>Strike the <code>noexcept</code> on these constructors in 99 [concurr.ts::futures.unique_future]/1-2 and 
99 [concurr.ts::futures.shared_future]/1-2, and optionally add a <i>Requires</i>: <code>rhs.valid() == true</code> 
paragraph.</p>
</blockquote>

<p><i>[2016-11-12, Issaquah]</i></p>

<p>Sat PM: We prefer alternative #2 - Move to review</p>

<p><i>[2018-06; Rapperswil, Wednesday evening session]</i></p>

<p>
DR: there is a sentence ended followed by an entirely new sentence<br/>
JM: so the period should be a semicolon in both edits<br/>
MC: ACTION I can make the change editorially<br/>
ACTION move to Ready 
</p>
<p><i>[2018-11, Adopted in San Diego]</i></p>



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

<blockquote class="note">
<p>
Alternative #2: Specify that an empty (<code>shared_</code>)<code>future</code> object is constructed if <code>rhs</code> is invalid, and adjust 
the postcondition accordingly.
</p>
</blockquote>
<ol>
<li><p>Edit 99 [concurr.ts::futures.unique_future] as indicated:</p>

<blockquote><pre>
future(future&lt;future&lt;R&gt;&gt;&amp;&amp; rhs) noexcept;
</pre>
<blockquote>
<p>
-3- <i>Effects</i>: <ins>If <code>rhs.valid() == false</code>, constructs an empty <code>future</code> object that does not 
refer to a shared state. Otherwise, c</ins><del>C</del>onstructs a <code>future</code> object from the shared state 
referred to by <code>rhs</code><del>. T</del><ins>; t</ins>he <code>future</code> becomes ready when one of the following occurs:
</p>
<ul>
<li><p>Both the <code>rhs</code> and <code>rhs.get()</code> are ready. The value or the exception from
<code>rhs.get()</code> is stored in the <code>future</code>'s shared state.</p></li>
<li><p><code>rhs</code> is ready but <code>rhs.get()</code> is invalid. An exception of type
<code>std::future_error</code>, with an error condition of <code>std::future_errc::broken_promise</code>
is stored in the <code>future</code>'s shared state.</p></li>
</ul>
<p>
-4- <i>Postconditions</i>:
</p>
<ul>
<li><p><del><code>valid() == true</code></del><ins><code>valid()</code> returns the same value as <code>rhs.valid()</code> prior to 
the constructor invocation.</ins>.</p></li>
<li><p><code>rhs.valid() == false</code>.</p></li>
</ul>
</blockquote>
</blockquote>
</li>

<li><p>Edit 99 [concurr.ts::futures.shared_future] as indicated:</p>

<blockquote><pre>
shared_future(future&lt;shared_future&lt;R&gt;&gt;&amp;&amp; rhs) noexcept;
</pre>
<blockquote>
<p>
-3- <i>Effects</i>: <ins>If <code>rhs.valid() == false</code>, constructs an empty <code>shared_future</code> object that does not 
refer to a shared state. Otherwise, c</ins><del>C</del>onstructs a <code>shared_future</code> object from the shared state 
referred to by <code>rhs</code><del>. T</del><ins>; t</ins>he <code>shared_future</code> becomes ready when one of the following occurs:
</p>
<ul>
<li><p>Both the <code>rhs</code> and <code>rhs.get()</code> are ready. The value or the exception from
<code>rhs.get()</code> is stored in the <code>shared_future</code>'s shared state.</p></li>
<li><p><code>rhs</code> is ready but <code>rhs.get()</code> is invalid. The <code>shared_future</code>
stores an exception of type <code>std::future_error</code>, with an error condition of
<code>std::future_errc::broken_promise</code>.</p></li>
</ul>
<p>
-4- <i>Postconditions</i>:
</p>
<ul>
<li><p><del><code>valid() == true</code></del><ins><code>valid()</code> returns the same value as <code>rhs.valid()</code> prior to 
the constructor invocation.</ins>.</p></li>
<li><p><code>rhs.valid() == false</code>.</p></li>
</ul>
</blockquote>
</blockquote>
</li>
</ol>





</body>
</html>
