<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2801: Default-constructibility of unique_ptr</title>
<meta property="og:title" content="Issue 2801: Default-constructibility of unique_ptr">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2801.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="2801"><a href="lwg-defects.html#2801">2801</a>. Default-constructibility of <code>unique_ptr</code></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#C++17">C++17</a>
 <b>Submitter:</b> United States <b>Opened:</b> 2016-11-09 <b>Last modified:</b> 2017-07-30</p>
<p><b>Priority: </b>2
</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#C++17">C++17</a> status.</p>
<p><b>Discussion:</b></p>
<p>
<b>Addresses US 122</b>
<p/>
<code>unique_ptr</code> should not satisfy <code>is_constructible_v&lt;unique_ptr&lt;T, D&gt;&gt;</code> 
unless <code>D</code> is <code>DefaultConstructible</code> and not a pointer type. This is 
important for interactions with <code>pair</code>, <code>tuple</code>, and <code>variant</code>
constructors that rely on the <code>is_default_constructible</code> trait.
</p>
<p>
Suggested resolution:
<p/>
Add a <i>Remarks:</i> clause to constrain the default 
constructor to not exist unless the <i>Requires</i> clause is 
satisfied.
</p>
<p><i>[Issues Telecon 16-Dec-2016]</i></p>

<p>Priority 2; Howard and Ville to provide wording.</p>

<p><i>[2016-12-24: Howard and Ville provided wording.]</i></p>


<p><i>[2017-03-02, Kona, STL comments and tweaks the wording]</i></p>

<p>
LWG discussed this issue, and we liked it, but we wanted to tweak the PR. I ran this past Ville 
(who drafted the PR with Howard), and he was in favor of tweaking this.
</p>

<p><i>[Kona 2017-03-02]</i></p>

<p>Accepted as Immediate to resolve NB comment.</p>


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

<ol>
<li>
<p>
Modify the synopsis in  20.3.1.3 <a href="https://wg21.link/unique.ptr.single">[unique.ptr.single]</a> as follows:
</p>
<blockquote>
<pre>
[&hellip;]
constexpr unique_ptr(nullptr_t) noexcept<ins>;</ins>
    <del>: unique_ptr() { }</del>
[&hellip;]
</pre>
</blockquote>
</li>

<li>
<p>
Modify 20.3.1.3.2 <a href="https://wg21.link/unique.ptr.single.ctor">[unique.ptr.single.ctor]</a> as follows:
</p>
<blockquote>

<pre>
constexpr unique_ptr() noexcept;
<ins>constexpr unique_ptr(nullptr_t) noexcept;</ins>
</pre>
<blockquote>
<p>
-1- <i>Requires:</i> <code>D</code> shall satisfy the requirements of <code>DefaultConstructible</code> (Table 22), and that construction
shall not throw an exception.
<p/>
-2- <i>Effects:</i> Constructs a <code>unique_ptr</code> object that owns nothing, value-initializing the stored pointer and
the stored deleter.
<p/>
-3- <i>Postconditions:</i> <code>get() == nullptr</code>. <code>get_deleter()</code> returns a reference to the stored deleter.
<p/>
-4- <i>Remarks:</i> <del>If this constructor is instantiated with a
pointer type or reference type for the template argument <code>D</code>,
the program is ill-formed.</del> <ins>If <code>is_pointer_v&lt;deleter_type&gt;</code> is <code>true</code> or
<code>is_default_constructible_v&lt;deleter_type&gt;</code> is
<code>false</code>, this constructor shall not participate in overload
resolution.</ins>
</p>
</blockquote>

<pre>
explicit unique_ptr(pointer p) noexcept;
</pre>
<blockquote>
<p>[&hellip;]</p>
<p>
-8- <i>Remarks:</i> <del>If this constructor is instantiated with a
pointer type or reference type for the template argument <code>D</code>,
the program is ill-formed.</del> <ins>If <code>is_pointer_v&lt;deleter_type&gt;</code> is <code>true</code> or
<code>is_default_constructible_v&lt;deleter_type&gt;</code> is
<code>false</code>, this constructor shall not participate in overload
resolution.</ins>
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>
Modify the synopsis in  20.3.1.4 <a href="https://wg21.link/unique.ptr.runtime">[unique.ptr.runtime]</a> as follows:
</p>
<blockquote>
<pre>
[&hellip;]
constexpr unique_ptr(nullptr_t) noexcept<ins>;</ins><del> : unique_ptr() { }</del>
[&hellip;]
</pre>
</blockquote>
</li>

<li>
<p>
Modify 20.3.1.4.2 <a href="https://wg21.link/unique.ptr.runtime.ctor">[unique.ptr.runtime.ctor]</a> as follows:
</p>
<blockquote>

<pre>
template &lt;class U&gt; explicit unique_ptr(U p) noexcept;
</pre>
<blockquote>
<p><ins>
This constructor behaves the same as the constructor that takes a
pointer parameter in the primary template except that the following
constraints are added for it to participate in overload resolution
</ins></p>
<ul>
<li><p><ins>
<code>U</code> is the same type as <code>pointer</code>, or
</ins></p></li>
<li><p><ins>
<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>.
</ins></p></li>
</ul>
</blockquote>
<pre>
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
pointer parameter in the primary template except that they shall not
participate in overload resolution unless either
</p>
</blockquote>
</blockquote>
</li>

</ol>






</body>
</html>
