<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3315: Correct Allocator Default Behavior</title>
<meta property="og:title" content="Issue 3315: Correct Allocator Default Behavior">
<meta property="og:description" content="C++ library issue. Status: C++20">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3315.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="3315"><a href="lwg-defects.html#3315">3315</a>. Correct Allocator Default Behavior</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> United States <b>Opened:</b> 2019-11-04 <b>Last modified:</b> 2021-02-25</p>
<p><b>Priority: </b>0
</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><b>Addresses US 162/US 163</b></p>

<p>
<b><a href="https://github.com/cplusplus/nbballot/issues/160">US 162</a>:</b>
<p/>
The default behavior for <code>a.destroy</code> is now to call <code>destroy_at</code>
<p/>
Proposed change:
<p/>
Replace "default" entry with: <code>destroy_at(c)</code>
</p>
<p>
<b><a href="https://github.com/cplusplus/nbballot/issues/161">US 163</a>:</b>
<p/>
The default behavior for <code>a.construct</code> is now to call <code>construct_at</code>
<p/>
Proposed change:
<p/>
Replace "default" entry with: <code>construct_at(c, std::forward&lt;Args&gt;(args)...)</code>
<p/>
<b>Dietmar K&uuml;hl:</b>
<p/>
In Table 34 [tab:cpp17.allocator] the behavior of <code>a.construct(c, args)</code> and
<code>a.destroy(c)</code> are described to have a default behavior of 
<code>::new ((void*)c) C(forward&lt;Args&gt;(args))</code> and <code>c-&gt;~C()</code>, respectively.
However, this table doesn't actually define what is happening if these operations are omitted: 
The behavior is provided when using an allocator is used via <code>std::allocator_traits</code> 
and is, thus, defined by the corresponding <code>std::allocator_traits</code> functions. These
functions are specified in 20.2.9.3 <a href="https://wg21.link/allocator.traits.members">[allocator.traits.members]</a> paragraphs 5 and 6 to call 
<code>construct_at(c, std::forward&lt;Args&gt;(args)</code> and <code>destroy_at(p)</code>, respectively.  
The text in the table should be updated to match the actual behavior.
</p>

<p><i>[2019-11 Status to Ready during Wednesday morning issue processing in Belfast.]</i></p>



<p id="res-3315"><b>Proposed resolution:</b></p>
<p>This wording is relative to <a href="https://wg21.link/n4835">N4835</a>.</p>

<ol>
<li><p>Modify 16.4.4.6 <a href="https://wg21.link/allocator.requirements">[allocator.requirements]</a>, Table [tab:cpp17.allocator] 
"<code><i>Cpp17Allocator</i></code> requirements" as indicated:</p>

<blockquote>
<table border="1">
<caption>Table 34 &mdash; <code><i>Cpp17Allocator</i></code> requirements [tab:cpp17.allocator]</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>a.construct(c, args)</code>
</td>
<td>
(not used)
</td>
<td>
<i>Effects:</i> Constructs an object of type <code>C</code> at <code>c</code>
</td>
<td>
<code><del>::new ((void*)c) C(</del><ins>construct_at(c, std::</ins>forward&lt;Args&gt;(args)...)</code>
</td>
</tr>

<tr>
<td>
<code>a.destroy(c)</code>
</td>
<td>
(not used)
</td>
<td>
<i>Effects:</i> Destroys the object at <code>c</code>
</td>
<td>
<code><del>c-&gt;~C()</del><ins>destroy_at(c)</ins></code>
</td>
</tr>

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

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





</body>
</html>
