<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2752: &quot;Throws:&quot; clauses of async and packaged_task are unimplementable</title>
<meta property="og:title" content="Issue 2752: &quot;Throws:&quot; clauses of async and packaged_task are unimplementable">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2752.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++17">C++17</a> status.</em></p>
<h3 id="2752"><a href="lwg-defects.html#2752">2752</a>. &quot;Throws:&quot; clauses of <code>async</code> and <code>packaged_task</code> are unimplementable</h3>
<p><b>Section:</b> 32.10.9 <a href="https://wg21.link/futures.async">[futures.async]</a>, 32.10.10.2 <a href="https://wg21.link/futures.task.members">[futures.task.members]</a> <b>Status:</b> <a href="lwg-active.html#C++17">C++17</a>
 <b>Submitter:</b> Billy Robert O'Neal III <b>Opened:</b> 2016-07-07 <b>Last modified:</b> 2017-07-30</p>
<p><b>Priority: </b>3
</p>
<p><b>View other</b> <a href="lwg-index-open.html#futures.async">active issues</a> in [futures.async].</p>
<p><b>View all other</b> <a href="lwg-index.html#futures.async">issues</a> in [futures.async].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++17">C++17</a> status.</p>
<p><b>Discussion:</b></p>
<p>
<code>std::async</code> is a request from the user for type erasure; as any given function gets passed to <code>async</code>
which returns only <code>future&lt;ReturnType&gt;</code>. Therefore, it needs to be able to allocate memory, as other issues
(e.g. LWG <a href="lwg-active.html#2202" title="Missing allocator support by async (Status: Deferred)">2202</a><sup><a href="https://cplusplus.github.io/LWG/issue2202" title="Latest snapshot">(i)</a></sup>) indicate. However, async's <em>Throws</em> clause doesn't allow an implementation to do
this, as it permits only <code>future_error</code>.
<p/>
<code>std::packaged_task</code>'s constructor allocates memory using a user supplied allocator. An implementation needs to
call the user's <code>allocate</code> to allocate such memory. The user's allocate function is not constrained to throwing
only <code>bad_alloc</code>; it can raise whatever it wants, but <code>packaged_task</code>'s constructor prohibits this.
</p>
<p><i>[2016-07 Chicago]</i></p>

<p>Alisdair thinks the third bullet is not quite right.</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<ol>
<li><p>Change 32.10.9 <a href="https://wg21.link/futures.async">[futures.async]</a> p6 to:</p>

<blockquote>
<p>
<em>Throws:</em> <code>system_error</code> if <code>policy == launch::async</code> and the implementation is unable to start a
new thread<ins>, or <code>std::bad_alloc</code> if memory for the internal data structures could not be allocated</ins>.
</p>
</blockquote>
</li>
<li><p>Change 32.10.10.2 <a href="https://wg21.link/futures.task.members">[futures.task.members]</a> p5 to:</p>

<blockquote>
<pre>
template &lt;class F&gt;
  packaged_task(F&amp;&amp; f);
template &lt;class F, class Allocator&gt;
  packaged_task(allocator_arg_t, const Allocator&amp; a, F&amp;&amp; f);
</pre>
<blockquote>
<p>
<em>Throws:</em>
</p>
<ol style="list-style-type: none">
<li>
<ins>(?) &mdash; A</ins><del>a</del>ny exceptions thrown by the copy or move constructor of <code>f</code><ins>.</ins><del>, or </del>
</li>
<li>
<ins>(?) &mdash; For the first version,</ins> <code>std::bad_alloc</code> if memory for the internal data structures
could not be allocated<ins>.</ins>
</li>
<li>
<ins>(?) &mdash; For the second version, any exceptions thrown by
<code>std::allocator_traits&lt;Allocator&gt;::template rebind&lt;<em>unspecified</em>&gt;::allocate</code></ins>.
</li>
</ol>
</blockquote>
</blockquote>
</li>
</ol>
</blockquote>

<p><i>[2016-08 Chicago]</i></p>

<p>Wed PM: Move to Tentatively Ready</p>


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

<ol>
<li><p>Change 32.10.9 <a href="https://wg21.link/futures.async">[futures.async]</a> p6 to:</p>

<blockquote>
<p>
<em>Throws:</em> <code>system_error</code> if <code>policy == launch::async</code> and the implementation is unable to start a
new thread<ins>, or <code>std::bad_alloc</code> if memory for the internal data structures could not be allocated</ins>.
</p>
</blockquote>
</li>
<li><p>Change 32.10.10.2 <a href="https://wg21.link/futures.task.members">[futures.task.members]</a> p5 to:</p>

<blockquote>
<pre>
template &lt;class F&gt;
  packaged_task(F&amp;&amp; f);
template &lt;class F, class Allocator&gt;
  packaged_task(allocator_arg_t, const Allocator&amp; a, F&amp;&amp; f);
</pre>
<blockquote>
<p>
<em>Throws:</em>
</p>
<ol style="list-style-type: none">
<li>
<ins>(?) &mdash; A</ins><del>a</del>ny exceptions thrown by the copy or move constructor of <code>f</code><ins>.</ins><del>, or </del>
</li>
<li>
<ins>(?) &mdash; For the first version,</ins> <code>std::bad_alloc</code> if memory for the internal data structures
could not be allocated<ins>.</ins>
</li>
<li>
<ins>(?) &mdash; For the second version, any exceptions thrown by
<code>std::allocator_traits&lt;Allocator&gt;::template rebind_traits&lt;<em>unspecified</em>&gt;::allocate</code></ins>.
</li>
</ol>
</blockquote>
</blockquote>
</li>
</ol>





</body>
</html>
