<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2799: noexcept-specifications in shared_future</title>
<meta property="og:title" content="Issue 2799: noexcept-specifications in shared_future">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2799.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="2799"><a href="lwg-defects.html#2799">2799</a>. <code>noexcept</code>-specifications in <code>shared_future</code></h3>
<p><b>Section:</b> 32.10.8 <a href="https://wg21.link/futures.shared.future">[futures.shared.future]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Zhihao Yuan <b>Opened:</b> 2016-11-11 <b>Last modified:</b> 2021-06-06</p>
<p><b>Priority: </b>2
</p>
<p><b>View all other</b> <a href="lwg-index.html#futures.shared.future">issues</a> in [futures.shared.future].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>
<p>
<b>Addresses GB 62</b>
<p/>
There is an implicit precondition on most <code>shared_future</code> operations that
<code>valid() == true</code>, 30.6.7p3. The list of exempted functions seems copied
directly from class <code>future</code>, and would also include copy operations for
<code>shared_futures</code>, which are copyable. Similarly, this would be a wide
contract that cannot throw, so those members would be marked <code>noexcept</code>.
</p>
<p>
Suggested resolution:
<p/>
Revise p3:
<p/>
"The effect of calling any member function other than the move constructor, the copy
constructor, the destructor, the move-assignment operator, the copy-assignment
operator, or <code>valid()</code> on a <code>shared_future</code> object for which
<code>valid() == false</code> is undefined." [&hellip;]
<p/>
Add <code>noexcept</code> specification to the copy constructor and copy-assignment operator,
in the class definition and where those members are specified.
</p>

<p><i>[2016-11-10, Zhihao Yuan comments and provides wording]</i></p>

<p>
This resolution should close LWG <a href="lwg-defects.html#2697" title="[concurr.ts] Behavior of future/shared_future unwrapping constructor when given an invalid future (Status: C++23)">2697</a><sup><a href="https://cplusplus.github.io/LWG/issue2697" title="Latest snapshot">(i)</a></sup> as well, but that one was filed
against concurrent TS.
</p>

<p><i>[Issues Telecon 16-Dec-2016]</i></p>

<p>This is also addressed (but in a slightly different way by <a href="https://wg21.link/p0516r0">P0516R0</a></p>

<p><i>[2017-11 Albuquerque Wednesday issue processing]</i></p>

<p>Resolved by <a href="https://wg21.link/p0516">P0516</a>, adopted in Issaquah.</p>


<p id="res-2799"><b>Proposed resolution:</b></p>
<p>This wording is relative to N4606.</p>

<blockquote class="note">
<p>
[Drafting note: This change supersedes the 1st among 3 edits in LWG <a href="lwg-defects.html#2556" title="Wide contract for future::share() (Status: C++17)">2556</a><sup><a href="https://cplusplus.github.io/LWG/issue2556" title="Latest snapshot">(i)</a></sup>,
please omit that edit and apply the one below.]
</p>
</blockquote>

<ol>
<li>
<p>Modify  [futures.unique_future]/3 as follows:</p>

<blockquote>
<p>
-3- The effect of calling <del>any member function other than the destructor, the move-assignment operator,
or <code>valid</code></del><ins>the member functions <code>get</code>, <code>wait</code>, <code>wait_for</code>, or
<code>wait_until</code></ins> on a <code>future</code> object for which <code>valid() == false</code> is undefined.
[<i>Note:</i> Implementations are encouraged to detect this case and throw an object of type
<code>future_error</code> with an error condition of <code>future_errc::no_state</code>. &mdash; <i>end note</i>]
</p>
</blockquote>
</li>

<li>
<p>Change  [futures.shared_future] as indicated:</p>

<blockquote>
<p>
-3- The effect of calling <del>any member function other than the destructor, the move-assignment operator, or
<code>valid()</code></del><ins>the member functions <code>get</code>, <code>wait</code>, <code>wait_for</code>, or
<code>wait_until</code></ins> on a <code>shared_future</code> object for which <code>valid() == false</code> is undefined.
[<i>Note:</i> Implementations are encouraged to detect this case and throw an object of type
<code>future_error</code> with an error condition of <code>future_errc::no_state</code>. &mdash; <i>end note</i>]
</p>
<blockquote><pre>
namespace std {
  template &lt;class R&gt;
  class shared_future {
  public:
    shared_future() noexcept;
    shared_future(const shared_future&amp; rhs) <ins>noexcept</ins>;
    shared_future(future&lt;R&gt;&amp;&amp;) noexcept;
    shared_future(shared_future&amp;&amp; rhs) noexcept;
    ~shared_future();
    shared_future&amp; operator=(const shared_future&amp; rhs) <ins>noexcept</ins>;
    shared_future&amp; operator=(shared_future&amp;&amp; rhs) noexcept;
    [&hellip;]
  };
  [&hellip;]
}
</pre></blockquote>
[&hellip;]
<pre>
shared_future(const shared_future&amp; rhs) <ins>noexcept</ins>;
</pre>
<blockquote>
<p>
-7- <i>Effects:</i> [&hellip;]
</p>
</blockquote>
[&hellip;]
<pre>
shared_future&amp; operator=(const shared_future&amp; rhs) <ins>noexcept</ins>;
</pre>
<blockquote>
<p>
-14- <i>Effects:</i> [&hellip;]
</p>
</blockquote>
</blockquote>
</li>
</ol>





</body>
</html>
