<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 950: unique_ptr converting ctor shouldn't accept array form</title>
<meta property="og:title" content="Issue 950: unique_ptr converting ctor shouldn't accept array form">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue950.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="950"><a href="lwg-defects.html#950">950</a>. <code>unique_ptr</code> converting ctor shouldn't accept array form</h3>
<p><b>Section:</b> 20.3.1.3.2 <a href="https://wg21.link/unique.ptr.single.ctor">[unique.ptr.single.ctor]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Howard Hinnant <b>Opened:</b> 2009-01-07 <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.ctor">issues</a> in [unique.ptr.single.ctor].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>
<p>
<code>unique_ptr</code>'s of array type should not convert to
<code>unique_ptr</code>'s which do not have an array type.
</p>

<blockquote><pre>
struct Deleter
{
   void operator()(void*) {}
};

int main()
{
   unique_ptr&lt;int[], Deleter&gt; s;
   unique_ptr&lt;int, Deleter&gt; s2(std::move(s));  <span style="color:#C80000">// should not compile</span>
}
</pre></blockquote>

<p><i>[
Post Summit:
]</i></p>


<blockquote>
<p>
Walter: Does the "diagnostic required" apply to both arms of the "and"?
</p>
<p>
Tom Plum: suggest to break into several sentences
</p>
<p>
Walter: suggest "comma" before the "and" in both places
</p>
<p>
Recommend Review.
</p>
</blockquote>

<p><i>[
Batavia (2009-05):
]</i></p>

<blockquote><p>
The post-Summit comments have been applied to the proposed resolution.
We now agree with the proposed resolution.
Move to Tentatively Ready.
</p></blockquote>

<p><i>[
2009-07 Frankfurt
]</i></p>


<blockquote><p>
Moved from Tentatively Ready to Open only because the wording needs to be
improved for <code>enable_if</code> type constraining, possibly following Robert's
formula.
</p></blockquote>

<p><i>[
2009-08-01 Howard updates wording and sets to Review.
]</i></p>


<p><i>[
2009-10 Santa Cruz:
]</i></p>


<blockquote><p>
Move to Ready.
</p></blockquote>

<p><i>[
2010-02-27 Pete Opens:
]</i></p>


<blockquote>
<p>
The proposed replacement text doesn't make sense.
</p>

<blockquote><p>
If <code>D</code> is a reference type, then <code>E</code> shall be the same type as
<code>D</code>, else this constructor shall not participate in overload resolution.
</p></blockquote>

<p>
This imposes two requirements. 1. If <code>D</code> is a reference type, <code>E</code>
has to be <code>D</code>. 2. If <code>D</code> is not a reference type, the constructor
shall not participate in overload resolution. If the latter apples, the language
in the preceding paragraph that this constructor shall not throw an exception if
<code>D</code> is not a reference type is superfluous. I suspect that's not the
intention, but I can't parse this text any other way.
</p>

<blockquote><p>
<code>U</code> shall not be an array type, else this constructor shall not
participate in overload resolution.
</p></blockquote>

<p>
I don't know what this means.
</p>
</blockquote>

<p><i>[
2010-02-27 Peter adds:
]</i></p>


<blockquote>
<p>
I think that the intent is (proposed text):
</p>

<blockquote>
<p>
<i>Remarks:</i> this constructor shall only participate in overload resolution
if:
</p>

<ul>
<li>
<code>unique_ptr&lt;U, E&gt;::pointer</code> is implicitly convertible to
<code>pointer</code>,
</li>

<li>
<code>U</code> is not an array type, and
</li>

<li>
if <code>D</code> is a reference type, <code>E</code> is the same type as <code>D</code>.
</li>
</ul>

</blockquote>

</blockquote>

<p><i>[
2010-02-28 Howard adds:
]</i></p>


<blockquote>
<p>
I like Peter's proposal.  Here is a tweak of it made after looking at my
implementation.  I believe this fixes a further defect not addressed by the
current proposed wording:
</p>

<blockquote>
<p>
<i>Remarks:</i> this constructor shall only participate in overload resolution
if:
</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, and
</li>

<li>
if <code>D</code> is a reference type, <code>E</code> is the same type as <code>D</code>,
else <code>E</code> shall be implicitly convertible to <code>D</code>.
</li>
</ul>

</blockquote>

</blockquote>

<p><i>[
2010 Pittsburgh:  Moved to NAD Editorial.  Rationale added below.
]</i></p>




<p><b>Rationale:</b></p>
<p>
Solved by
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3073.html">N3073</a>.
</p>


<p id="res-950"><b>Proposed resolution:</b></p>
<p>
Change 20.3.1.3.2 <a href="https://wg21.link/unique.ptr.single.ctor">[unique.ptr.single.ctor]</a>:
</p>

<blockquote>
<pre>
template &lt;class U, class E&gt; unique_ptr(unique_ptr&lt;U, E&gt;&amp;&amp; u);
</pre>
<blockquote>
<p>
-20- <i>Requires:</i> If <code>D</code> is not a reference type,
construction of the deleter <code>D</code> from an rvalue of type <code>E</code>
shall be well formed and shall not throw an exception. <del>If <code>D</code> is
a reference type, then <code>E</code> shall be the same type as <code>D</code>
(diagnostic required). <code>unique_ptr&lt;U, E&gt;::pointer</code> shall be
implicitly convertible to <code>pointer</code>. [<i>Note:</i> These requirements
imply that <code>T</code> and <code>U</code> are complete types. &mdash; <i>end note</i>]</del>
</p>

<p><ins>
<i>Remarks:</i> If <code>D</code> is
a reference type, then <code>E</code> shall be the same type as <code>D</code>, else this
constructor shall not participate in overload resolution. <code>unique_ptr&lt;U, E&gt;::pointer</code> shall be
implicitly convertible to <code>pointer</code>, else this
constructor shall not participate in overload resolution. <code>U</code> shall not be
an array type, else this
constructor shall not participate in overload resolution. [<i>Note:</i> These requirements
imply that <code>T</code> and <code>U</code> are complete types. &mdash; <i>end note</i>]
</ins></p>

</blockquote>
</blockquote>

<p>
Change 20.3.1.3.4 <a href="https://wg21.link/unique.ptr.single.asgn">[unique.ptr.single.asgn]</a>:
</p>

<blockquote>
<pre>
template &lt;class U, class E&gt; unique_ptr&amp; operator=(unique_ptr&lt;U, E&gt;&amp;&amp; u);
</pre>
<blockquote>
<p>
-6- <i>Requires:</i> Assignment of the deleter <code>D</code> from an rvalue
<code>D</code> shall not throw an exception. <del><code>unique_ptr&lt;U,
E&gt;::pointer</code> shall be implicitly convertible to <code>pointer</code>.
[<i>Note:</i> These requirements imply that <code>T</code> and <code>U</code>
are complete types. &mdash; <i>end note</i>]</del>
</p>

<p><ins>
<i>Remarks:</i> <code>unique_ptr&lt;U,
E&gt;::pointer</code> shall be implicitly convertible to <code>pointer</code>, else this
operator shall not participate in overload resolution.
<code>U</code> shall not be an array type, else this
operator shall not participate in overload resolution.
[<i>Note:</i> These requirements imply that <code>T</code> and <code>U</code>
are complete types. &mdash; <i>end note</i>]
</ins></p>

</blockquote>
</blockquote>






</body>
</html>
