<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2047: Incorrect "mixed" move-assignment semantics of unique_ptr</title>
<meta property="og:title" content="Issue 2047: Incorrect &quot;mixed&quot; move-assignment semantics of unique_ptr">
<meta property="og:description" content="C++ library issue. Status: C++14">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2047.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="2047"><a href="lwg-defects.html#2047">2047</a>. Incorrect "mixed" move-assignment semantics of <code>unique_ptr</code></h3>
<p><b>Section:</b> 20.3.1.3.4 <a href="https://wg21.link/unique.ptr.single.asgn">[unique.ptr.single.asgn]</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-04-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#unique.ptr.single.asgn">issues</a> in [unique.ptr.single.asgn].</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>The semantics described in 20.3.1.3.4 <a href="https://wg21.link/unique.ptr.single.asgn">[unique.ptr.single.asgn]</a> p. 6</p>
<blockquote><p>
<i>Effects</i>: Transfers ownership from <code>u</code> to <code>*this</code> as if [&hellip;] followed 
by an assignment from <code>std::forward&lt;D&gt;(u.get_deleter())</code>.
</p></blockquote>
<p>
contradicts to the pre-conditions described in p. 4:
</p>
<blockquote><p>
<i>Requires</i>: If E is not a reference type, assignment of the deleter from an rvalue of type <code>E</code> shall be
well-formed and shall not throw an exception. Otherwise, <code>E</code> is a reference type and assignment of the
deleter from an lvalue of type <code>E</code> shall be well-formed and shall not throw an exception.
</p></blockquote>
<p>
Either the pre-conditions are incorrect or the semantics should be an assignment from
<code>std::forward&lt;<span style="color:red;font-weight:bolder">E</span>&gt;(u.get_deleter())</code>, instead.
</p>
<p>It turns out that this contradiction is due to an incorrect transcription from the proposed
resolution of <a href="lwg-defects.html#983" title="unique_ptr reference deleters should not be moved from (Status: Resolved)">983</a><sup><a href="https://cplusplus.github.io/LWG/issue983" title="Latest snapshot">(i)</a></sup> to the finally accepted proposal 
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3073.html">n3073</a> (see
bullet 12) as confirmed by Howard Hinnant, thus the type argument provided to <code>std::forward</code>
must be fixed as indicated.
</p>

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

<p>
Move to Ready
</p>



<p id="res-2047"><b>Proposed resolution:</b></p>

<p>This wording is relative to the FDIS.</p>

<ol>
<li><p>Edit 20.3.1.3.4 <a href="https://wg21.link/unique.ptr.single.asgn">[unique.ptr.single.asgn]</a> p. 6 as indicated:</p>

<blockquote><pre>
template &lt;class U, class E&gt; unique_ptr&amp; operator=(unique_ptr&lt;U, E&gt;&amp;&amp; u) noexcept;
</pre><blockquote><p>
4 - <i>Requires</i>: If <code>E</code> is not a reference type, assignment of the deleter from an rvalue 
of type <code>E</code> shall be well-formed and shall not throw an exception. Otherwise, <code>E</code> is a 
reference type and assignment of the deleter from an lvalue of type <code>E</code> shall be well-formed and 
shall not throw an exception.
<p/>
5 - <i>Remarks</i>: This operator shall not participate in overload resolution unless:</p>
<ul>
<li><code>unique_ptr&lt;U, E&gt;::pointer</code> is implicitly convertible to <code>pointer</code> and</li>
<li><code>U</code> is not an array type.</li>
</ul>
<p>
6 - <i>Effects</i>: Transfers ownership from <code>u</code> to <code>*this</code> as if by calling 
<code>reset(u.release())</code> followed by an assignment from <code>std::forward&lt;<del>D</del><ins>E</ins>&gt;(u.get_deleter())</code>.
<p/>
7 - <i>Returns</i>: <code>*this</code>.
</p>
</blockquote>
</blockquote>

</li>
</ol>






</body>
</html>
