<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2505: auto_ptr_ref creation requirements underspecified</title>
<meta property="og:title" content="Issue 2505: auto_ptr_ref creation requirements underspecified">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2505.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="2505"><a href="lwg-defects.html#2505">2505</a>. <code>auto_ptr_ref</code> creation requirements underspecified</h3>
<p><b>Section:</b> 99 [auto.ptr.conv] <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Hubert Tong <b>Opened:</b> 2015-05-28 <b>Last modified:</b> 2020-09-06</p>
<p><b>Priority: </b>4
</p>
<p><b>View all other</b> <a href="lwg-index.html#auto.ptr.conv">issues</a> in [auto.ptr.conv].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>
<p>
In C++14 sub-clause 99 [auto.ptr.conv], there appears to be no requirement that the formation of an 
<code>auto_ptr_ref&lt;Y&gt;</code> from an <code>auto_ptr&lt;X&gt;</code> is done only when <code>X*</code> can be implicitly 
converted to <code>Y*</code>.
<p/>
For example, I expect formation of the <code>auto_ptr_ref&lt;A&gt;</code> from the prvalue of type <code>auto_ptr&lt;B&gt;</code> 
to be invalid in the case below (but the wording does not seem to be there):
</p>
<blockquote><pre>
#include &lt;memory&gt;

struct A { };
struct B { } b;

std::auto_ptr&lt;B&gt; apB() { return std::auto_ptr&lt;B&gt;(&amp;b); }
int main() {
  std::auto_ptr&lt;A&gt; apA(apB());
  apA.release();
}
</pre></blockquote>
<p>
The behaviour of the implementation in question on the case presented above is to compile and execute it successfully 
(which is what the C++14 wording implies). The returned value from <code>apA.release()</code> is essentially 
<code>reinterpret_cast&lt;A*&gt;(&amp;b)</code>.
<p/>
There is nothing in the specification of
</p>
<blockquote><pre>
template &lt;class X&gt;
template &lt;class Y&gt; operator auto_ptr&lt;X&gt;::auto_ptr_ref&lt;Y&gt;() throw();
</pre></blockquote>
<p>
which implies that <code>X*</code> should be implicitly convertible to <code>Y*</code>.
<p/>
The implementation in question uses the <code>reinterpret_cast</code> interpretation even when <code>Y</code> is an accessible, 
unambiguous base class of <code>X</code>; the result thereof is that no offset adjustment is performed.
</p>

<p><i>[2015-07, Telecon]</i></p>

<p>
Marshall to resolve.
</p>

<p><i>[2016-03-16, Alisdair Meredith comments]</i></p>

<p>
This issue is a defect in a component we have actively removed
from the standard. I can't think of a clearer example of something
that is no longer a defect!
</p>

<p><i>[2016-08-03, Alisdair Meredith comments]</i></p>

<p>
As C++17 removes <code>auto_ptr</code>, I suggest closing this issue as closed by paper 
<a href="https://wg21.link/n4190">N4190</a>.
</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<p>
This wording is relative to ISO/IEC 14882:2014(E).
</p>

<ol>
<li><p>Change 99 [auto.ptr.conv] as indicated:</p>

<blockquote>
<pre>
template&lt;class Y&gt; operator auto_ptr_ref&lt;Y&gt;() throw();
</pre>
<blockquote>
<p>
<ins>-?- <i>Requires</i>: <code>X*</code> can be implicitly converted to <code>Y*</code>.</ins>
<p/>
-3- <i>Returns</i>: An <code>auto_ptr_ref&lt;Y&gt;</code> that holds <code>*this</code>.
<p/>
<ins>-?- <i>Notes</i>: Because <code>auto_ptr_ref</code> is present for exposition only, the only way to invoke this function 
is by calling one of the <code>auto_ptr</code> conversions which take an <code>auto_ptr_ref</code> as an argument. Since all 
such conversions will call <code>release()</code> on <code>*this</code> (in the form of the <code>auto_ptr</code> that the 
<code>auto_ptr_ref</code> holds a reference to), an implementation of this function may cause instantiation of said 
<code>release()</code> function without changing the semantics of the program.</ins>
</p>
</blockquote>
<pre>
template&lt;class Y&gt; operator auto_ptr&lt;Y&gt;() throw();
</pre>
<blockquote>
<p>
<ins>-?- <i>Requires</i>: <code>X*</code> can be implicitly converted to <code>Y*</code>.</ins>
<p/>
-4- <i>Effects</i>: Calls <code>release()</code>.
<p/>
-5- <i>Returns</i>: An <code>auto_ptr&lt;Y&gt;</code> that holds the pointer returned from <code>release()</code>.
</p>
</blockquote>
</blockquote>
</li>
</ol>
</blockquote>

<p><i>[2016-08 - Chicago]</i></p>

<p>Thurs AM: Moved to Tentatively Resolved</p>


<p id="res-2505"><b>Proposed resolution:</b></p>
<p>
Resolved by acceptance of <a href="https://wg21.link/n4190">N4190</a>.
</p>





</body>
</html>
