<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2169: Missing reset() requirements in unique_ptr specialization</title>
<meta property="og:title" content="Issue 2169: Missing reset() requirements in unique_ptr specialization">
<meta property="og:description" content="C++ library issue. Status: C++14">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2169.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="2169"><a href="lwg-defects.html#2169">2169</a>. Missing <code>reset()</code> requirements in <code>unique_ptr</code> specialization</h3>
<p><b>Section:</b> 20.3.1.4.5 <a href="https://wg21.link/unique.ptr.runtime.modifiers">[unique.ptr.runtime.modifiers]</a> <b>Status:</b> <a href="lwg-active.html#C++14">C++14</a>
 <b>Submitter:</b> Geoffrey Romer <b>Opened:</b> 2012-07-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.runtime.modifiers">issues</a> in [unique.ptr.runtime.modifiers].</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>
In 20.3.1.4.5 <a href="https://wg21.link/unique.ptr.runtime.modifiers">[unique.ptr.runtime.modifiers]</a>/p1-2 of N3376, the description of <code>reset()</code> in the 
array specialization of <code>unique_ptr</code> partially duplicates the description of the base template method 
(as specified in 20.3.1.3.6 <a href="https://wg21.link/unique.ptr.single.modifiers">[unique.ptr.single.modifiers]</a>/p3-5), but lacks some significant requirements. 
Specifically, the text introduced in LWG <a href="lwg-defects.html#998" title="Smart pointer referencing its owner (Status: C++11)">998</a><sup><a href="https://cplusplus.github.io/LWG/issue998" title="Latest snapshot">(i)</a></sup>, and item 13 of LWG <a href="lwg-defects.html#762" title="std::unique_ptr requires complete type? (Status: CD1)">762</a><sup><a href="https://cplusplus.github.io/LWG/issue762" title="Latest snapshot">(i)</a></sup>, is present 
only in the base template, not the specialization.
<p/>
This gives the appearance that these requirements specifically do not apply to the specialization, which I 
don't believe is correct or intended: the issue of <code>reset()</code> operation order addressed by LWG <a href="lwg-defects.html#998" title="Smart pointer referencing its owner (Status: C++11)">998</a><sup><a href="https://cplusplus.github.io/LWG/issue998" title="Latest snapshot">(i)</a></sup> 
applies just as much to the derived template as to the base template, and the derived template has just as 
much need to rely on <code>get_deleter()(get())</code> being well-defined, well-formed, and not throwing exceptions 
(arguably some of those properties follow from the fact that <code>T</code> is required to be a complete type, but 
not all).
<p/>
Assuming the derived template's <code>reset()</code> semantics are intended to be identical to the base template's, 
there is no need to explicitly specify the semantics of <code>reset(pointer p)</code> at all (since 
20.3.1.4 <a href="https://wg21.link/unique.ptr.runtime">[unique.ptr.runtime]</a>/3 specifies "Descriptions are provided below only for member functions that 
have behavior different from the primary template."), and <code>reset(nullptr_t p)</code> can be specified by 
reference to the 'pointer' overload. This is more concise, and eliminates any ambiguity about intentional vs. 
accidental discrepancies.
</p>

<p><i>[2012-10 Portland: Move to Ready]</i></p>

<p>
<del>This resolution looks blatantly wrong, as it seems to do nothing but defer to primary template
where we should describe the contract here.</del>
</p>

<p>
Ongoing discussion points out that the primary template has a far more carefully worded semantic
for <code>reset(p)</code> that we would want to copy here.
</p>

<p>
STL points out that we need the <code>nullptr</code> overload for this dynamic-array form, as there is
a deleted member function template that exists to steal overloads of pointer-to-derived, avoiding
undifined behavior, so we need the extra overload.
</p>

<p>
Finally notice that there is blanket wording further up the clause saying we describe only changes
from the primary template, so the proposed wording is in fact exactly correct.  Move to Ready.
</p>

<p><i>[2013-04-20 Bristol]</i></p>




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

<p>Change 20.3.1.4.5 <a href="https://wg21.link/unique.ptr.runtime.modifiers">[unique.ptr.runtime.modifiers]</a> as indicated:</p>

<blockquote><pre>
<del>void reset(pointer p = pointer()) noexcept;</del>
void reset(nullptr_t p) noexcept;
</pre><blockquote>
<p>
-1- <i>Effects</i>: <del>If <code>get() == nullptr</code> there are no effects. Otherwise <code>get_deleter()(get())</code></del>
<ins>Equivalent to <code>reset(pointer())</code></ins>.
<p/>
<del>-2- <i>Postcondition</i>: <code>get() == p</code>.</del>
</p>
</blockquote></blockquote>






</body>
</html>
