<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1309: Missing expressions for Move/CopyConstructible</title>
<meta property="og:title" content="Issue 1309: Missing expressions for Move/CopyConstructible">
<meta property="og:description" content="C++ library issue. Status: C++11">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1309.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="1309"><a href="lwg-defects.html#1309">1309</a>. Missing expressions for <code>Move/CopyConstructible</code></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> Daniel Kr&uuml;gler <b>Opened:</b> 2010-02-03 <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>
Table 33 &mdash; MoveConstructible requirements [moveconstructible] and
Table 34 &mdash; CopyConstructible requirements [copyconstructible] support
solely the following expression:
</p>

<blockquote><pre>
T t(rv)
</pre></blockquote>

<p>
where <code>rv</code> is defined to be as "non-const rvalue of type <code>T</code>"  and
<code>t</code> as a "modifiable lvalue of type <code>T</code>" in 16.4.4.2 <a href="https://wg21.link/utility.arg.requirements">[utility.arg.requirements]</a>/1.
</p>

<p>
This causes two different defects:
</p>

<ol style="list-style-type:lower-alpha">
<li>
<p>
We cannot move/copy-initialize a <em>const</em> lvalue of type <code>T</code> as in:
</p>

<blockquote><pre>
int get_i();

const int i1(get_i());
</pre></blockquote>

<p>
both in Table 33 and in Table 34.
</p>
</li>

<li>
<p>
The single support for
</p>

<blockquote><pre>
T t(rv)
</pre></blockquote>

<p>
in case of <code>CopyConstructible</code> means that we cannot provide an
lvalue as a source of a copy as in
</p>

<blockquote><pre>
const int&amp; get_lri();

int i2(get_lri());
</pre></blockquote>
</li>
</ol>

<p>
I believe this second defect is due to the fact that this single
expression supported <em>both</em> initialization situations according
to the old (implicit) lvalue reference -&gt; rvalue reference
conversion rules.
</p>

<p>
Finally [copyconstructible] refers to some name <code>u</code> which is not part of
the expression, and both [copyconstructible] and [moveconstructible] should
support construction expressions from temporaries - this would be a stylistic
consequence in the light of the new <code>DefaultConstructible</code> requirements
and compared with existing requirements (see e.g. Container requirements or the
output/forward iterator requirements)..
</p>

<p><i>[
2010-02-09 Moved to Tentatively Ready after 5 positive votes on c++std-lib.
]</i></p>


<p><i>[
2010-02-10 Reopened. The proposed wording of <a href="lwg-defects.html#1283" title="MoveConstructible and MoveAssignable need clarification
of moved-from state (Status: Resolved)">1283</a><sup><a href="https://cplusplus.github.io/LWG/issue1283" title="Latest snapshot">(i)</a></sup> has been
merged here.
]</i></p>


<p><i>[
2010-02-10 Moved to Tentatively Ready after 5 positive votes on c++std-lib.
]</i></p>




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

<ol>

<li>
<p>
Change 16.4.4.2 <a href="https://wg21.link/utility.arg.requirements">[utility.arg.requirements]</a>/1 as indicated: <i>[This change
suggestion is motivated to make type descriptions clearer: First, <code>a</code>,
<code>b</code>, and <code>c</code> <em>may</em> also be non-<code>const T</code>. Second, <code>u</code>
is described in a manner consistent with the container requirements tables.]</i>
</p>

<blockquote><p>
1 The template definitions in the C++ standard library refer to various named
requirements whose details are set out in tables 31-38. In these tables,
<code>T</code> is a<ins>n object or reference</ins> type to be supplied by a C++
program instantiating a template; <code>a</code>, <code>b</code>, and <code>c</code> are
values of type <ins>(possibly</ins> <code>const<ins>)</ins> T</code>; <code>s</code> and
<code>t</code> are modifiable lvalues of type <code>T</code>; <code>u</code> <ins>denotes an
identifier;</ins> <del>is a value of type (possibly <code>const</code>) <code>T</code>;
and</del> <code>rv</code> is a<ins>n</ins> <del>non-const</del> rvalue of type
<code>T</code><ins>; and <code>v</code> is an lvalue of type (possibly <code>const</code>)
<code>T</code> or an rvalue of type <code>const T</code></ins>.
</p></blockquote>
</li>

<li>
<p>
In 16.4.4.2 <a href="https://wg21.link/utility.arg.requirements">[utility.arg.requirements]</a> Table 33 ([moveconstructible])
change as indicated <i>[Note: The symbol <code>u</code> is defined to be either a
const or a non-const value and is the right one we need here]</i>:
</p>

<blockquote>
<table border="1">
<caption>Table 33 &mdash; <code>MoveConstructible</code> requirements [moveconstructible]</caption>

<tr>
<th>Expression</th>
<th>Post-condition</th>
</tr>

<tr>
<td>
<code>T <del>t</del><ins>u</ins>(rv)<ins>;</ins></code>
</td>
<td>
<code><del>t</del><ins>u</ins></code> is equivalent
to the value of <code>rv</code> before the construction
</td>
</tr>

<tr>
<td><ins><code>T(rv)</code></ins></td>
<td><ins><code>T(rv)</code> is equivalent to the value of <code>rv</code> before the
construction</ins></td>
</tr>

<tr>
<td colspan="2">[<i>Note:</i>
<del>There is no requirement on the value of <code>rv</code> after the
construction.</del>
<ins><code>rv</code> remains a valid object.  Its state is unspecified.</ins>
&mdash; <i>end note</i>]</td>
</tr>
</table>
</blockquote>
</li>

<li>
<p>
In 16.4.4.2 <a href="https://wg21.link/utility.arg.requirements">[utility.arg.requirements]</a> Table 34 ([copyconstructible])
change as indicated <i>[Note: The symbol <code>u</code> is defined to be either a
const or a non-const value and is the right one we need here. The expressions
using <code>a</code> are recommended to ensure that lvalues are supported as sources
of the copy expression]</i>:
</p>

<blockquote>
<table border="1">
<caption>Table 34 &mdash; <code>CopyConstructible</code> requirements [copyconstructible]<br/>
<ins>(in addition to <code>MoveConstructible</code>)</ins></caption>

<tr>
<th>Expression</th>
<th>Post-condition</th>
</tr>

<tr>
<td>
<code>T <del>t</del><ins>u</ins>(<del>r</del>v)<ins>;</ins></code>
</td>
<td>
the value of <code><del>u</del><ins>v</ins></code>
is unchanged and is equivalent to <code><del>t</del><ins>u</ins></code>
</td>
</tr>

<tr>
<td>
<ins><code>T(v)</code></ins>
</td>
<td><ins>the value of <code>v</code> is unchanged and is equivalent to <code>T(v)</code></ins>
</td>
</tr>

<tr>
<td colspan="2"><del>[<i>Note:</i> A type that satisfies the
<code>CopyConstructible</code> requirements also satisfies the <code>MoveConstructible</code>
requirements. &mdash; <i>end note</i>]</del></td>
</tr>

</table>
</blockquote>

</li>

<li>
<p>
In Table 35 &mdash; MoveAssignable requirements [moveassignable] change as
indicated:
</p>

<blockquote>

<table border="1">
<caption>Table 35 &mdash; <code>MoveAssignable</code> requirements <b>[moveassignable]</b></caption>
<tr>
<th>Expression</th>
<th>Return type</th>
<th>Return value</th>
<th>Post-condition</th>
</tr>
<tr>
<td>
<code>t = rv</code>
</td>
<td>
<code>T&amp;</code>
</td>
<td>
<code>t</code>
</td>
<td>
<code>t</code> is equivalent to the value of <code>rv</code> before the assigment.
</td>
</tr>
<tr>
<td colspan="4">
[<i>Note:</i>
<del>There is no requirement on the value of <code>rv</code> after the
assignment.</del>
<ins><code>rv</code> remains a valid object.  Its state is unspecified.</ins>
&mdash; <i>end note</i>]
</td>
</tr>
</table>

</blockquote>
</li>

<li>
<p>
In 16.4.4.2 <a href="https://wg21.link/utility.arg.requirements">[utility.arg.requirements]</a> change Table 36 as indicated:
</p>

<blockquote>
<table border="1">
<caption>Table 36 &mdash; <code>CopyAssignable</code> requirements
[copyassignable]<br/><ins>(in addition to <code>MoveAssignable</code>)</ins></caption>

<tr>
<th>Expression</th>
<th>Return type</th>
<th>Return value</th>
<th>Post-condition</th>
</tr>

<tr>
<td><code>t = <del>u</del><ins>v</ins></code></td>
<td><code>T&amp;</code></td>
<td><code>t</code></td>
<td><code>t</code> is equivalent to <code><del>u</del><ins>v</ins></code>, the value of
<code><del>u</del><ins>v</ins></code> is unchanged</td>
</tr>

<tr>
<td colspan="4"><del>[<i>Note:</i> A type that satisfies the <code>CopyAssignable</code>
requirements also satisfies the <code>MoveAssignable</code> requirements. &mdash;
<i>end note</i>]</del></td>
</tr>

</table>
</blockquote>
</li>
</ol>






</body>
</html>
