<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2067: packaged_task should have deleted copy c'tor with const parameter</title>
<meta property="og:title" content="Issue 2067: packaged_task should have deleted copy c'tor with const parameter">
<meta property="og:description" content="C++ library issue. Status: C++14">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2067.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++14">C++14</a> status.</em></p>
<h3 id="2067"><a href="lwg-defects.html#2067">2067</a>. <code>packaged_task</code> should have deleted copy c'tor with const parameter</h3>
<p><b>Section:</b> 32.10.10 <a href="https://wg21.link/futures.task">[futures.task]</a> <b>Status:</b> <a href="lwg-active.html#C++14">C++14</a>
 <b>Submitter:</b> Daniel Kr&uuml;gler <b>Opened:</b> 2011-06-16 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#futures.task">issues</a> in [futures.task].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++14">C++14</a> status.</p>
<p><b>Discussion:</b></p>
<p>
Class template <code>packaged_task</code> is a move-only type with the following form of the
deleted copy operations:
</p>
<blockquote><pre>
packaged_task(packaged_task&amp;) = delete;
packaged_task&amp; operator=(packaged_task&amp;) = delete;
</pre></blockquote>
<p>
Note that the argument types are non-const. This does not look like a typo to me,
this form seems to exist from the very first proposing paper on 
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2276.html">N2276</a>.
Using either of form of the copy-constructor did not make much difference before the 
introduction of defaulted special member functions, but it makes now an observable 
difference. This was brought to my attention by a question on a German C++ newsgroup 
where the question was raised why the following code does not compile on a recent
gcc:
</p>
<blockquote><pre>
#include &lt;utility&gt;
#include &lt;future&gt;
#include &lt;iostream&gt;
#include &lt;thread&gt;

int main(){
  std::packaged_task&lt;void()&gt; someTask([]{ std::cout &lt;&lt; std::this_thread::get_id() &lt;&lt; std::endl; });
  std::thread someThread(std::move(someTask)); // <span style="color:#C80000">Error here</span>
  // Remainder omitted
}
</pre></blockquote>
<p>
It turned out that the error was produced by the instantiation of some return type
of <code>std::bind</code> which used a defaulted copy-constructor, which leads to a
const declaration conflict with [class.copy] p8.
<p/>
Some aspects of this problem are possibly core-language related, but I consider it
more than a service to programmers, if the library would declare the usual form of
the copy operations (i.e. those with const first parameter type) as deleted for
<code>packaged_task</code> to prevent such problems.
<p/>
A similar problem exists for class template <code>basic_ostream</code> in 31.7.6.2 <a href="https://wg21.link/ostream">[ostream]</a>:
</p>
<blockquote><pre>
namespace std {
  template &lt;class charT, class traits = char_traits&lt;charT&gt; &gt;
  class basic_ostream : virtual public basic_ios&lt;charT,traits&gt; {
    [&hellip;]

    // 27.7.3.3 Assign/swap
    basic_ostream&amp; operator=(basic_ostream&amp; rhs) = delete;
    basic_ostream&amp; operator=(const basic_ostream&amp;&amp; rhs);
    void swap(basic_ostream&amp; rhs);
};
</pre></blockquote>
<p>
albeit this could be considered as an editorial swap of copy and move
assignment operator, I suggest to fix this as part of this issue as well.
</p>

<p><i>[
2011 Bloomington.
]</i></p>


<p>
Move to Ready.
</p>



<p id="res-2067"><b>Proposed resolution:</b></p>
<p>This wording is relative to the FDIS.</p>
<ol>
<li><p>Modify the class template <code>basic_ostream</code> synopsis in 31.7.6.2 <a href="https://wg21.link/ostream">[ostream]</a>
as indicated (Note: The prototype signature of the move assignment operator in 31.7.6.2.3 <a href="https://wg21.link/ostream.assign">[ostream.assign]</a>
is fine):</p>

<blockquote><pre>
namespace std {
  template &lt;class charT, class traits = char_traits&lt;charT&gt; &gt;
  class basic_ostream : virtual public basic_ios&lt;charT,traits&gt; {
    [&hellip;]

    // 27.7.3.3 Assign/swap
    basic_ostream&amp; operator=(<ins>const</ins> basic_ostream&amp; rhs) = delete;
    basic_ostream&amp; operator=(<del>const</del> basic_ostream&amp;&amp; rhs);
    void swap(basic_ostream&amp; rhs);
};
</pre></blockquote>
</li>

<li><p>Modify the class template <code>packaged_task</code> synopsis in 32.10.10 <a href="https://wg21.link/futures.task">[futures.task]</a> p2
as indicated:</p>

<blockquote><pre>
namespace std {
  template&lt;class&gt; class packaged_task; <i>// undefined</i>

  template&lt;class R, class... ArgTypes&gt;
  class packaged_task&lt;R(ArgTypes...)&gt; {
  public:
    [&hellip;]
  
    <i>// no copy</i>
    packaged_task(<ins>const</ins> packaged_task&amp;) = delete;
    packaged_task&amp; operator=(<ins>const</ins> packaged_task&amp;) = delete;
    
    [&hellip;]
  };
  [&hellip;]
}
</pre></blockquote>
</li>
</ol>





</body>
</html>
