<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3159: &sect;[unique.ptr.single] requirements on deleter may be too strict</title>
<meta property="og:title" content="Issue 3159: &sect;[unique.ptr.single] requirements on deleter may be too strict">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3159.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#New">New</a> status.</em></p>
<h3 id="3159"><a href="lwg-active.html#3159">3159</a>. &sect;[unique.ptr.single] requirements on deleter may be too strict</h3>
<p><b>Section:</b> 20.3.1.3 <a href="https://wg21.link/unique.ptr.single">[unique.ptr.single]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
 <b>Submitter:</b> Jonathan Wakely <b>Opened:</b> 2018-09-17 <b>Last modified:</b> 2018-10-06</p>
<p><b>Priority: </b>3
</p>
<p><b>View other</b> <a href="lwg-index-open.html#unique.ptr.single">active issues</a> in [unique.ptr.single].</p>
<p><b>View all other</b> <a href="lwg-index.html#unique.ptr.single">issues</a> in [unique.ptr.single].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
<p><b>Discussion:</b></p>
<p>
20.3.1.3 <a href="https://wg21.link/unique.ptr.single">[unique.ptr.single]</a> p1 says:
</p>
<blockquote><p>
The default type for the template parameter <code>D</code> is <code>default_delete</code>. A client-supplied template argument 
<code>D</code> shall be a function object type (19.14), lvalue reference to function, or lvalue reference to function object 
type for which, given a value <code>d</code> of type <code>D</code> and a value ptr of type <code>unique_ptr&lt;T, D&gt;::pointer</code>, 
the expression <code>d(ptr)</code> is valid and has the effect of disposing of the pointer as appropriate for that deleter.
</p></blockquote>
<p>
That means this is undefined:
</p>
<blockquote><pre>
#include &lt;memory&gt;

struct IncompleteBase;

struct Deleter {
  void operator()(IncompleteBase*) const;
};

struct IncompleteDerived;

struct X {
  std::unique_ptr&lt;IncompleteDerived, Deleter&gt; p;
  ~X();
};
</pre></blockquote>
<p>
<code>unique_ptr::pointer</code> is <code>IncompleteDerived*</code>, but <code>is_invocable&lt;Deleter, IncompleteDerived*&gt;</code> 
is unknowable until the type is complete (see LWG <a href="lwg-active.html#3099" title="is_assignable&lt;Incomplete&amp;, Incomplete&amp;&gt; (Status: Open)">3099</a><sup><a href="https://cplusplus.github.io/LWG/issue3099" title="Latest snapshot">(i)</a></sup> etc).
<p/>
The intention is that <code>IncompleteDerived</code> only needs to be complete when the deleter is invoked, which is in the 
definition of <code>X::~X()</code> for this example. But the requirement for <code>d(ptr)</code> to be valid requires a complete type. 
If the <code>unique_ptr</code> implementation adds <code>static_assert(is_invocable_v&lt;D, pointer&gt;)</code> to enforce the 
requirement, the example above fails to compile. GCC recently added that assertion.
<p/>
Do we want to relax that requirement, or do we want to force the code above to define <code>Deleter::pointer</code> as 
<code>IncompleteBase*</code> so that the <code>is_invocable</code> condition can be checked?
<p/>
The destructor and <code>reset</code> member function already require that the deleter can be invoked (and that <i>Requires:</i> 
element will be turned into a <i>Mandates:</i> one soon). We can just remove that requirement from the preamble for the 
class template, or say that the expression only needs to be valid when the destructor and <code>reset</code> member are 
instantiated. We could also rephrase it in terms of <code>is_invocable_v&lt;D, unique_ptr&lt;T, D&gt;::pointer&gt;</code>.
</p>

<p><i>[2018-10 Reflector prioritization]</i></p>

<p>Set Priority to 3</p>


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





</body>
</html>
