<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2228: Missing SFINAE rule in unique_ptr templated assignment</title>
<meta property="og:title" content="Issue 2228: Missing SFINAE rule in unique_ptr templated assignment">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2228.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="2228"><a href="lwg-defects.html#2228">2228</a>. Missing <em>SFINAE</em> rule in <code>unique_ptr</code> templated assignment</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#Resolved">Resolved</a>
 <b>Submitter:</b> Geoffrey Romer <b>Opened:</b> 2012-12-20 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>3
</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#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>

<p>
20.3.1.3.4 <a href="https://wg21.link/unique.ptr.single.asgn">[unique.ptr.single.asgn]</a>/5 permits <code>unique_ptr</code>'s templated assignment operator to participate 
in overload resolution even when incompatibilities between <code>D</code> and <code>E</code> will render the result ill-formed, 
but the corresponding templated copy constructor is removed from the overload set in those situations (see the third 
bullet point of 20.3.1.3.2 <a href="https://wg21.link/unique.ptr.single.ctor">[unique.ptr.single.ctor]</a>/19). This asymmetry is confusing, and presumably unintended; 
it may lead to situations where constructing one <code>unique_ptr</code> from another is well-formed, but assigning from 
the same <code>unique_ptr</code> would be ill-formed.
<p/>
There is a slight coupling between this and LWG <a href="lwg-defects.html#2118" title="[CD] unique_ptr for array does not support cv qualification conversion of actual argument (Status: Resolved)">2118</a><sup><a href="https://cplusplus.github.io/LWG/issue2118" title="Latest snapshot">(i)</a></sup>, in that my PR for LWG <a href="lwg-defects.html#2118" title="[CD] unique_ptr for array does not support cv qualification conversion of actual argument (Status: Resolved)">2118</a><sup><a href="https://cplusplus.github.io/LWG/issue2118" title="Latest snapshot">(i)</a></sup> incorporates 
equivalent wording in the specification of the templated assignment operator for the array specialization; the two PRs 
are logically independent, but if my PR for <a href="lwg-defects.html#2118" title="[CD] unique_ptr for array does not support cv qualification conversion of actual argument (Status: Resolved)">2118</a><sup><a href="https://cplusplus.github.io/LWG/issue2118" title="Latest snapshot">(i)</a></sup> is accepted but the above PR is not, the discrepancy 
between the base template and the specialization could be confusing.
</p>

<p>
<strong>Previous resolution [SUPERSEDED]:</strong>
</p>
<blockquote class="note">
<p>This wording is relative to N3485.</p>
<ol>
<li><p>Revise 20.3.1.3.4 <a href="https://wg21.link/unique.ptr.single.asgn">[unique.ptr.single.asgn]</a> p5 as follows:</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><p><code>unique_ptr&lt;U, E&gt;::pointer</code> is implicitly convertible to <code>pointer</code> and</p></li>
<li><p><code>U</code> is not an array type<del>.</del><ins>, and</ins></p></li>
<li><p><ins>either <code>D</code> is a reference type and <code>E</code> is the same type as <code>D</code>, or <code>D</code> is 
not a reference type and <code>E</code> is implicitly convertible to <code>D</code>.</ins></p></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;E&gt;(u.get_deleter())</code>.
<p/>
-7- <i>Returns</i>: <code>*this</code>.
</p>
</blockquote></blockquote>

</li>
</ol>

</blockquote>

<p><i>[2013-03-15 Issues Teleconference]</i></p>

<p>
Moved to Review.
</p>
<p>
The wording looks good, but we want a little more time than the telecon permits to be truly comfortable.
We expect this issue to resolve fairly easily in Bristol.
</p>

<p><i>[2015-05-18, Howard comments]</i></p>

<p>
Updated proposed wording has been provided in <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4366.html">N4366</a>.
</p>

<p><i>[2015-05, Lenexa]</i></p>

<p>
Straw poll: send <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4366.html">N4366</a> to full committee, 
with both fixes from the sections "What is the correct fix?" and "<code>unique_ptr&lt;T[]&gt;</code> needs the correct fix too"
</p>



<p id="res-2228"><b>Proposed resolution:</b></p>
<p>
Resolved by accepting <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4366.html">N4366</a>.
</p>





</body>
</html>
