<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 127: auto_ptr&lt;&gt; conversion issues</title>
<meta property="og:title" content="Issue 127: auto_ptr&lt;&gt; conversion issues">
<meta property="og:description" content="C++ library issue. Status: TC1">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue127.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#TC1">TC1</a> status.</em></p>
<h3 id="127"><a href="lwg-defects.html#127">127</a>. auto_ptr&lt;&gt; conversion issues</h3>
<p><b>Section:</b> 99 [auto.ptr] <b>Status:</b> <a href="lwg-active.html#TC1">TC1</a>
 <b>Submitter:</b> Greg Colvin <b>Opened:</b> 1999-02-17 <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#auto.ptr">issues</a> in [auto.ptr].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#TC1">TC1</a> status.</p>
<p><b>Discussion:</b></p>
<p>There are two problems with the current <code>auto_ptr</code> wording
in the standard: </p>

<p>First, the <code>auto_ptr_ref</code> definition cannot be nested
because <code>auto_ptr&lt;Derived&gt;::auto_ptr_ref</code> is unrelated to
<code>auto_ptr&lt;Base&gt;::auto_ptr_ref</code>.  <i>Also submitted by
Nathan Myers, with the same proposed resolution.</i></p>

<p>Second, there is no <code>auto_ptr</code> assignment operator taking an
<code>auto_ptr_ref</code> argument. </p>

<p>I have discussed these problems with my proposal coauthor, Bill
Gibbons, and with some compiler and library implementors, and we
believe that these problems are not desired or desirable implications
of the standard. </p>

<p>25 Aug 1999: The proposed resolution now reflects changes suggested
by Dave Abrahams, with Greg Colvin's concurrence; 1) changed
&quot;assignment operator&quot; to &quot;public assignment
operator&quot;, 2) changed effects to specify use of release(), 3)
made the conversion to auto_ptr_ref const. </p>

<p>2 Feb 2000: Lisa Lippincott comments: [The resolution of] this issue
states that the conversion from auto_ptr to auto_ptr_ref should
be const.  This is not acceptable, because it would allow
initialization and assignment from _any_ const auto_ptr!  It also
introduces an implementation difficulty in writing this conversion
function -- namely, somewhere along the line, a const_cast will be
necessary to remove that const so that release() may be called.  This
may result in undefined behavior [7.1.5.1/4]. The conversion
operator does not have to be const, because a non-const implicit
object parameter may be bound to an rvalue [13.3.3.1.4/3]
[13.3.1/5]. </p>

  <p>Tokyo: The LWG removed the following from the proposed resolution:</p>

  <p>In 21.3.6 <a href="https://wg21.link/meta.unary">[meta.unary]</a>, paragraph 2, and 21.3.6.4 <a href="https://wg21.link/meta.unary.prop">[meta.unary.prop]</a>, 
  paragraph 2, make the conversion to auto_ptr_ref const:</p>
  <blockquote>
    <pre>template&lt;class Y&gt; operator auto_ptr_ref&lt;Y&gt;() const throw();</pre>
  </blockquote>


<p id="res-127"><b>Proposed resolution:</b></p>
<p>In 21.3.6 <a href="https://wg21.link/meta.unary">[meta.unary]</a>, paragraph 2, move
the <code>auto_ptr_ref</code> definition to namespace scope.</p>

<p>In 21.3.6 <a href="https://wg21.link/meta.unary">[meta.unary]</a>, paragraph 2, add
a public assignment operator to the <code>auto_ptr</code> definition: </p>

<blockquote>
  <pre>auto_ptr&amp; operator=(auto_ptr_ref&lt;X&gt; r) throw();</pre>
</blockquote>

<p>Also add the assignment operator to 21.3.6.4 <a href="https://wg21.link/meta.unary.prop">[meta.unary.prop]</a>: </p>

<blockquote>
  <pre>auto_ptr&amp; operator=(auto_ptr_ref&lt;X&gt; r) throw()</pre>

  <p><b>Effects:</b> Calls <code>reset(p.release())</code> for the <code>auto_ptr
  p</code> that <code>r</code> holds a reference to.<br/>
  <b>Returns: </b><code>*this</code>.</p>

</blockquote>





</body>
</html>
