<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 753: Move constructor in draft</title>
<meta property="og:title" content="Issue 753: Move constructor in draft">
<meta property="og:description" content="C++ library issue. Status: C++11">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue753.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++11">C++11</a> status.</em></p>
<h3 id="753"><a href="lwg-defects.html#753">753</a>. Move constructor in draft</h3>
<p><b>Section:</b> 16.4.4.2 <a href="https://wg21.link/utility.arg.requirements">[utility.arg.requirements]</a> <b>Status:</b> <a href="lwg-active.html#C++11">C++11</a>
 <b>Submitter:</b> Yechezkel Mett <b>Opened:</b> 2007-10-14 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View other</b> <a href="lwg-index-open.html#utility.arg.requirements">active issues</a> in [utility.arg.requirements].</p>
<p><b>View all other</b> <a href="lwg-index.html#utility.arg.requirements">issues</a> in [utility.arg.requirements].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++11">C++11</a> status.</p>
<p><b>Discussion:</b></p>
<p>
The draft standard n2369 uses the term <i>move constructor</i> in a few
places, but doesn't seem to define it.
</p>

<p>
<code>MoveConstructible</code> requirements are defined in Table 33 in 16.4.4.2 <a href="https://wg21.link/utility.arg.requirements">[utility.arg.requirements]</a> as
follows:
</p>

<blockquote>
<table border="1">
<caption><code>MoveConstructible</code> requirements</caption>
<tr>
<th>expression</th> <th>post-condition</th>
</tr>
<tr>
<td><code>T t = rv</code></td> <td><code>t</code> is equivalent to the value of <code>rv</code> before the construction</td>
</tr>
<tr>
<td colspan="2">[<i>Note:</i> There is no requirement on the value of <code>rv</code> after the
construction. <i>-- end note</i>]</td>
</tr>
</table>
</blockquote>

<p>
(where <code>rv</code> is a non-const rvalue of type <code>T</code>).
</p>

<p>
So I assume the move constructor is the constructor that would be used
in filling the above requirement.
</p>

<p>
For <code>vector::reserve</code>, <code>vector::resize</code> and the <code>vector</code> modifiers given in
23.3.13.5 <a href="https://wg21.link/vector.modifiers">[vector.modifiers]</a> we have
</p>

<blockquote><p>
<i>Requires:</i> If <code>value_type</code> has a move constructor, that constructor shall
not throw any exceptions.
</p></blockquote>

<p>
Firstly "If <code>value_type</code> has a move constructor" is superfluous; every
type which can be put into a <code>vector</code> has a move constructor (a copy
constructor is also a move constructor). Secondly it means that for
any <code>value_type</code> which has a throwing copy constructor and no other move
constructor these functions cannot be used -- which I think will come
as a shock to people who have been using such types in <code>vector</code> until
now!
</p>

<p>
I can see two ways to correct this. The simpler, which is presumably
what was intended, is to say "If <code>value_type</code> has a move constructor and
no copy constructor, the move constructor shall not throw any
exceptions" or "If <code>value_type</code> has a move constructor which changes the
value of its parameter,".
</p>

<p>
The other alternative is add to <code>MoveConstructible</code> the requirement that
the expression does not throw. This would mean that not every type
that satisfies the <code>CopyConstructible</code> requirements also satisfies the
<code>MoveConstructible</code> requirements. It would mean changing requirements in
various places in the draft to allow either <code>MoveConstructible</code> or
<code>CopyConstructible</code>, but I think the result would be clearer and
possibly more concise too.
</p>


<p id="res-753"><b>Proposed resolution:</b></p>
<p>
Add new defintions to  [definitions]:
</p>

<blockquote>
<p>
<b>move constructor</b>
</p>
<p>
a constructor which accepts only rvalue arguments of that type, and modifies the rvalue as a
side effect during the construction.
</p>
<p>
<b>move assignment operator</b>
</p>
<p>
an assignment operator which accepts only rvalue arguments of that type, and modifies the rvalue as a
side effect during the assignment.
</p>
<p>
<b>move assignment</b>
</p>
<p>
use of the move assignment operator.
</p>
</blockquote>

<p><i>[
Howard adds post-Bellevue:
]</i></p>


<blockquote>
<p>
Unfortunately I believe the wording recommended by the LWG in Bellevue is incorrect.  <code>reserve</code> et. al. 
will use a move constructor if one is available, else it will use a copy constructor.  A type may have both.  
If the move constructor is used, it must not throw.  If the copy constructor is used, it can throw.  The 
sentence in the proposed wording is correct without the recommended insertion.  The Bellevue LWG recommended 
moving this issue to Ready.  I am unfortunately pulling it back to Open.  But I'm drafting wording to atone 
for this egregious action. :-)
</p>
</blockquote>






</body>
</html>
