<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 4160: packaged_task should reject rvalue reference return types</title>
<meta property="og:title" content="Issue 4160: packaged_task should reject rvalue reference return types">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue4160.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="4160"><a href="lwg-active.html#4160">4160</a>. <code>packaged_task</code> should reject rvalue reference return types</h3>
<p><b>Section:</b> 32.10.10.1 <a href="https://wg21.link/futures.task.general">[futures.task.general]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
 <b>Submitter:</b> Casey Carter <b>Opened:</b> 2024-09-28 <b>Last modified:</b> 2025-02-07</p>
<p><b>Priority: </b>3
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
<p><b>Discussion:</b></p>
<p>
<code class='backtick'>promise</code>, <code class='backtick'>future</code>, and <code class='backtick'>shared_future</code> all refuse rvalue reference types as template arguments 
(e.g., 32.10.6 <a href="https://wg21.link/futures.promise">[futures.promise]</a> paragraphs 1 and 2), but <code>packaged_task&lt;meow&amp;&amp;()&gt;</code> 
violates no requirements. Its member <code class='backtick'>get_future</code> returns <code>future&lt;meow&amp;&amp;&gt;</code>, 
which is ill-formed, but the other member functions appear to be callable. Nonetheless, at least MSVCSTL, 
libc++, and libstdc++ all fail to compile simple uses of <code class='backtick'>packaged_task</code> with a function type that has 
an rvalue reference return type (see <a href="https://www.godbolt.org/z/5E18nn896">https://www.godbolt.org/z/5E18nn896</a>).
<p/>
Presumably the design intent &mdash; which the implementers all inferred &mdash; is that <code class='backtick'>packaged_task</code> 
should be ill-formed when <code class='backtick'>get_future</code> is not instantiable. The spec should say so explicitly rather than 
relying on the fact that one of the basis operations is unusable.
</p>

<p><i>[2025-02-07; Reflector poll]</i></p>

<p>
Set priority to 3 after reflector poll.
</p>
<p>
"Shouldn't it be ill-formed only if instantiated?"
</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">

<p>
This wording is relative to <a href="https://wg21.link/N4988" title=" Working Draft, Programming Languages — C++">N4988</a>.
</p>

<ol>
<li><p>Modify 32.10.10.1 <a href="https://wg21.link/futures.task.general">[futures.task.general]</a> as indicated:</p>

<blockquote>
<p>
[&hellip;]
<p/>
-2- When the <code>packaged_task</code> object is invoked, its stored task is invoked and the result 
(whether normal or exceptional) stored in the shared state. Any futures that share the shared state 
will then be able to access the stored result.
</p>
<blockquote>
<pre>
namespace std {
  template&lt;class&gt; class packaged_task; // <i>not defined</i>
  
  template&lt;class R, class... ArgTypes&gt;
  class packaged_task&lt;R(ArgTypes...)&gt; {
    [&hellip;]
  };
  
  template&lt;class R, class... ArgTypes&gt;
  packaged_task(R (*)(ArgTypes...)) -&gt; packaged_task&lt;R(ArgTypes...)&gt;;
  
  template&lt;class F&gt; packaged_task(F) -&gt; packaged_task&lt;<i>see below</i>&gt;;
}
</pre>
</blockquote>
<p>
<ins>-?- The program is ill-formed if <code>R</code> is an rvalue reference type.</ins>
</p>
</blockquote>
</li>
</ol>
</blockquote>

<p><i>[2025-02-07; Jonathan provides improved wording]</i></p>




<p id="res-4160"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/N5001" title=" Working Draft, Programming Languages — C++">N5001</a>.
</p>

<ol>
<li><p>Modify 32.10.10.1 <a href="https://wg21.link/futures.task.general">[futures.task.general]</a> as indicated:</p>

<blockquote>
<p>
[&hellip;]
<p/>
-2- When the <code>packaged_task</code> object is invoked, its stored task is invoked and the result 
(whether normal or exceptional) stored in the shared state. Any futures that share the shared state 
will then be able to access the stored result.
</p>
<blockquote>
<pre>
namespace std {
  template&lt;class&gt; class packaged_task; // <i>not defined</i>

  template&lt;class R, class... ArgTypes&gt;
  class packaged_task&lt;R(ArgTypes...)&gt; {
    [&hellip;]
  };

  template&lt;class R, class... ArgTypes&gt;
  packaged_task(R (*)(ArgTypes...)) -&gt; packaged_task&lt;R(ArgTypes...)&gt;;

  template&lt;class F&gt; packaged_task(F) -&gt; packaged_task&lt;<i>see below</i>&gt;;
}
</pre>
</blockquote>
<p>
<ins>-?-
If the definition of a specialization
<code>packaged_task&lt;R(Args...)&gt;</code> is instantiated for
an rvalue reference type <code class='backtick'>R</code>, the program is ill-formed.
</ins>
</p>
</blockquote>
</li>
</ol>





</body>
</html>
