<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2593: Moved-from state of Allocators</title>
<meta property="og:title" content="Issue 2593: Moved-from state of Allocators">
<meta property="og:description" content="C++ library issue. Status: C++20">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2593.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++20">C++20</a> status.</em></p>
<h3 id="2593"><a href="lwg-defects.html#2593">2593</a>. Moved-from state of Allocators</h3>
<p><b>Section:</b> 16.4.4.6 <a href="https://wg21.link/allocator.requirements">[allocator.requirements]</a> <b>Status:</b> <a href="lwg-active.html#C++20">C++20</a>
 <b>Submitter:</b> David Krauss <b>Opened:</b> 2016-02-19 <b>Last modified:</b> 2021-02-25</p>
<p><b>Priority: </b>4
</p>
<p><b>View other</b> <a href="lwg-index-open.html#allocator.requirements">active issues</a> in [allocator.requirements].</p>
<p><b>View all other</b> <a href="lwg-index.html#allocator.requirements">issues</a> in [allocator.requirements].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++20">C++20</a> status.</p>
<p><b>Discussion:</b></p>
<p>
16.4.4.6 <a href="https://wg21.link/allocator.requirements">[allocator.requirements]</a> suggests that the moved-from state of an allocator may be unequal to its 
previous state. Such a move constructor would break most container implementations, which move-construct the 
embedded allocator along with a compressed pair. Even if a moved-from container is empty, it should still 
subsequently allocate from the same resource pool as it did before.
</p>
<blockquote><pre>
std::vector&lt;int, pool&gt; a(500, my_pool);
auto b = std::move(a); // b uses my_pool too.
a.resize(500); // should still use my_pool.
</pre></blockquote>

<p><i>[2016-02, Jacksonville]</i></p>

<p>Marshall will see if this can be resolved editorially.</p>

<p>
After discussion, the editors and I decided that this could not be handled editorially. 
The bit about a moved-from state of an allocator being the same as the original state is a
normative change. I submitted a <a href="https://github.com/cplusplus/draft/pull/727">pull request</a>
to handle the mismatched variables in the table.
</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<p>
This wording is relative to N4567.
</p>

<ol>
<li><p>Change 16.4.4.6 <a href="https://wg21.link/allocator.requirements">[allocator.requirements]</a>, Table 28 &mdash; "Allocator requirements" as indicated:
<blockquote class="note">
<p>
Note there's an editorial error in Table 28 in that line and the surrounding ones. The left column was apparently 
updated to use <code>u</code> and the right column is still using <code>a</code>/<code>a1</code>/<code>b</code>.
</p>
</blockquote>
</p>

<blockquote>
<table border="1">
<caption>Table 28 &mdash; Allocator requirements</caption>
<tr>
<th>Expression</th>
<th>Return type</th>
<th>Assertion&#47;note<br/>pre-&#47;post-condition</th>
<th>Default</th>
</tr>

<tr>
<td colspan="4" align="center">
<code>&hellip;</code>
</td>
</tr>

<tr>
<td>
<code>X u(move(a));<br/>
X u = move(a);</code>
</td>
<td></td>
<td>
Shall not exit via an exception.
post: <ins><code>u</code> is equal to <code>a</code> and equal to the prior value of <code>a</code></ins><del><code>a1</code> 
equals the prior value of <code>a</code></del>.
</td>
<td>
</td>
</tr>

<tr>
<td colspan="4" align="center">
<code>&hellip;</code>
</td>
</tr>

</table>
</blockquote>

</li>
</ol>

</blockquote>

<p><i>[2016-06-20, Oulu, Daniel comments]</i></p>

<p>
According to the current working draft, the situation has changed due to changes performed by the project editor, the revised 
resolution has been adjusted to N4594.
</p>

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

<p>Thurs AM: Moved to LEWG, as this decision (should allocators only be copyable, not movable) is design.</p>

<p><i>[2017-02 in Kona, LEWG responds]</i></p>

<p>Alisdair Meredith says that if you have a do-not-propagate-on-move-assignment, 
then the move of the allocator must compare equal to the original.</p>
<p>Have a data structure where all allocators are equal. 
Construct an element somewhere else moving from inside the container 
(which doesn't have a POCMA trait); you don't want the allocator of the
moved-from element to now be different. So in that case, the allocator's 
move constructor must behave the same as copy.</p>
<p>We don't need to go as far as this issue, but going that far is ok for Bloomberg.</p>

<p><i>[2017-06-02 Issues Telecon]</i></p>

<p>We discussed containers that have sentinel nodes, etc, and so might have to 
allocate/deallocate using a moved-from allocator - and decided that we didn't
want any part of that</p>
<p>Adjusted the wording slightly, and moved to Tentatively Ready</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<p>
This wording is relative to N4594.
</p>

<ol>
<li><p>Change 16.4.4.6 <a href="https://wg21.link/allocator.requirements">[allocator.requirements]</a>, Table 28 &mdash; "Allocator requirements" as indicated:</p>

<blockquote>
<table border="1">
<caption>Table 28 &mdash; Allocator requirements</caption>
<tr>
<th>Expression</th>
<th>Return type</th>
<th>Assertion&#47;note<br/>pre-&#47;post-condition</th>
<th>Default</th>
</tr>

<tr>
<td colspan="4" align="center">
<code>&hellip;</code>
</td>
</tr>

<tr>
<td>
<code>X u(std::move(a));<br/>
X u = std::move(a);</code>
</td>
<td></td>
<td>
Shall not exit via an exception.
post: <ins><code>u</code> is equal to <code>a</code> and equal to the prior value of <code>a</code></ins><del><code>u</code> is equal to the prior
value of <code>a</code>.</del>.
</td>
<td>
</td>
</tr>

<tr>
<td colspan="4" align="center">
<code>&hellip;</code>
</td>
</tr>

</table>
</blockquote>

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



<p id="res-2593"><b>Proposed resolution:</b></p>
<p>
This wording is relative to N4594.
</p>

<ol>
<li><p>Change 16.4.4.6 <a href="https://wg21.link/allocator.requirements">[allocator.requirements]</a>, Table 28 &mdash; "Allocator requirements" as indicated:</p>

<blockquote>
<table border="1">
<caption>Table 28 &mdash; Allocator requirements</caption>
<tr>
<th>Expression</th>
<th>Return type</th>
<th>Assertion&#47;note<br/>pre-&#47;post-condition</th>
<th>Default</th>
</tr>

<tr>
<td colspan="4" align="center">
<code>&hellip;</code>
</td>
</tr>

<tr>
<td>
<code>X u(std::move(a));<br/>
X u = std::move(a);</code>
</td>
<td></td>
<td>
Shall not exit via an exception.
post: <ins>The value of <code>a</code> is unchanged and is equal to <code>u</code></ins><del><code>u</code> is equal to the prior value of <code>a</code></del>.
</td>
<td>
</td>
</tr>

<tr>
<td colspan="4" align="center">
<code>&hellip;</code>
</td>
</tr>

</table>
</blockquote>

</li>
</ol>






</body>
</html>
