<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2520: N4089 broke initializing unique_ptr&lt;T[]&gt; from a nullptr</title>
<meta property="og:title" content="Issue 2520: N4089 broke initializing unique_ptr&lt;T[]&gt; from a nullptr">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2520.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++17">C++17</a> status.</em></p>
<h3 id="2520"><a href="lwg-defects.html#2520">2520</a>. N4089 broke initializing <code>unique_ptr&lt;T[]&gt;</code> from a <code>nullptr</code></h3>
<p><b>Section:</b> 20.3.1.4.2 <a href="https://wg21.link/unique.ptr.runtime.ctor">[unique.ptr.runtime.ctor]</a> <b>Status:</b> <a href="lwg-active.html#C++17">C++17</a>
 <b>Submitter:</b> Ville Voutilainen <b>Opened:</b> 2015-07-19 <b>Last modified:</b> 2017-07-30</p>
<p><b>Priority: </b>2
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++17">C++17</a> status.</p>
<p><b>Discussion:</b></p>
<p>
According to the wording in 20.3.1.4.2 <a href="https://wg21.link/unique.ptr.runtime.ctor">[unique.ptr.runtime.ctor]</a>/1,
this won't work:
</p>
<blockquote><pre>
unique_ptr&lt;int[], DeleterType&gt; x{nullptr, DeleterType{}};
</pre></blockquote>
<p>
<code>U</code> is not the same type as <code>pointer</code>, so the first bullet will not do.<br/>
<code>U</code> is not a pointer type, so the second bullet will not do.
<p/>
An easy fix would be to add a new bullet after the first bullet, like so:
</p>
<ul>
<li><p><code>U</code> is the same type as <code>pointer</code>, or</p></li>
<li><p><ins><code>U</code> is <code>nullptr_t</code>, or</ins></p></li>
<li><p><code>pointer</code> is the same type as <code>element_type*</code>, [&hellip;]</p></li>
</ul>

<p><i>[2015-10, Kona Saturday afternoon]</i></p>

<p>MC: Is it the right fix? </p>
<p>GR: It'd be awefully surprising if we had an interface that accepts null pointer values but not std::nullptr_t. I think the PR is good.</p>
<p>STL: Are any of the assignments and reset affected? [No, they don't operate on explicit {pointer, deleter} pairs.]</p>
<p>VV: This is already shipping, has been implemented, has been tested and works fine.</p>
<p>Move to Tentatively ready.</p>


<p id="res-2520"><b>Proposed resolution:</b></p>
<p>
This wording is relative to N4527.
</p>

<ol>
<li><p>Change 20.3.1.4.2 <a href="https://wg21.link/unique.ptr.runtime.ctor">[unique.ptr.runtime.ctor]</a> as indicated:</p>
<blockquote>
<pre>
template &lt;class U&gt; explicit unique_ptr(U p) noexcept;
template &lt;class U&gt; unique_ptr(U p, <i>see below</i> d) noexcept;
template &lt;class U&gt; unique_ptr(U p, <i>see below</i> d) noexcept;
</pre>
<blockquote>
<p>
-1- These constructors behave the same as the constructors that take a <code>pointer</code> parameter in the primary
template except that they shall not participate in overload resolution unless either
</p>
<ul>
<li><p><code>U</code> is the same type as <code>pointer</code>, or</p></li>
<li><p><ins><code>U</code> is <code>nullptr_t</code>, or</ins></p></li>
<li><p><code>pointer</code> is the same type as <code>element_type*</code>, <code>U</code> is a pointer type <code>V*</code>, and 
<code>V(*)[]</code> is convertible to <code>element_type(*)[]</code>.</p></li>
</ul>
</blockquote>
</blockquote>
</li>
</ol>





</body>
</html>
