<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2447: Allocators and volatile-qualified value types</title>
<meta property="og:title" content="Issue 2447: Allocators and volatile-qualified value types">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2447.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++17">C++17</a> status.</em></p>
<h3 id="2447"><a href="lwg-defects.html#2447">2447</a>. Allocators and <code>volatile</code>-qualified value types</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++17">C++17</a>
 <b>Submitter:</b> Daniel Kr&uuml;gler <b>Opened:</b> 2014-10-16 <b>Last modified:</b> 2017-07-30</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++17">C++17</a> status.</p>
<p><b>Discussion:</b></p>
<p>
According to Table 27 &mdash; "Descriptive variable definitions" which is used to define the symbols used in the
allocator requirements table within 16.4.4.6 <a href="https://wg21.link/allocator.requirements">[allocator.requirements]</a> we have the following constraints for
the types <code>T, U, C</code>:
</p>
<blockquote><p>
any non-const object type (3.9)
</p></blockquote>
<p>
This wording can be read to allow instead a <code>volatile</code>-qualified value type such as <code>volatile int</code>.
<p/>
The nearest-by way of fixing this would be to add "non-<code>volatile</code>" as additional constraint to this table
row.
<p/>
Another choice would be to think of requiring that allocators must be capable to handle any <code><i>cv</i></code>-qualified
value types. This would make all currently existing allocators non-conforming that can't handle <code><i>cv</i></code>-qualified 
value types, so I'm not suggesting to follow that route.
<p/>
A less radical step would be to allow <code><i>cv</i></code>-qualified types just for <code>C</code> (which is used to specify the
functions <code>construct</code> and <code>destroy</code> and where does not even exist any requirement that <code>C</code> actually 
is related to the value type of the allocator at all). This seemingly extension would be harmless because as of p8 of the
same sub-clause "An allocator may constrain the types on which it can be instantiated and the arguments for which its
<code>construct</code> member may be called."
<p/>
This differs from the requirements imposed on the types <code>T</code> and <code>U</code> which both refer to value types of allocators.
<p/>
The proposed wording attempts to separate the two classes of requirements.
</p>

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

<ol>
<li><p>Change 16.4.4.6 <a href="https://wg21.link/allocator.requirements">[allocator.requirements]</a>, Table 27 &mdash; "Descriptive variable definitions", as indicated:</p>
<blockquote>
<table border="1">
<caption>Table 27 &mdash; Descriptive variable definitions</caption>
<tr>
<th>Variable</th>
<th>Definition</th>
</tr>

<tr>
<td>
<code>T, U<del>, C</del></code>
</td>
<td>
any non-<del>const</del><ins><code>const</code> and non-<code>volatile</code></ins> object type (3.9)
</td>
</tr>

<tr>
<td>
<ins><code>C</code></ins>
</td>
<td>
<ins>any object type</ins>
</td>
</tr>

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

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

<li><p>Change 16.4.4.6 <a href="https://wg21.link/allocator.requirements">[allocator.requirements]</a> p8 as indicated: (This wording change is intended to
fix an obvious asymmetry between <code>construct</code> and <code>destroy</code> which I believe is not intended)</p>

<blockquote><p>
-8- An allocator may constrain the types on which it can be instantiated and the arguments for which its
<code>construct</code> <ins>or <code>destroy</code></ins> member<ins>s</ins> may be called. If a type cannot be 
used with a particular allocator, the allocator class or the call to <code>construct</code> <ins>or <code>destroy</code></ins> 
may fail to instantiate.
</p></blockquote>
</li>
</ol>

</blockquote>

<p><i>[2014-11, Urbana]</i></p>

<p>
JW: say "cv-unqualified" instead?<br/>
JW: very nervous about allowing construct on const-types, because of the cast to (non-const) <code>void*</code><br/>
MA: should we just make the minimal fix?<br/>
STL: don't break <code>C</code> out for special treatment<br/>
New proposed resolution: just change "non-const" to "cv-unqualified". Keep addition of <code>destroy</code> later. 
</p>

<p><i>[2015-02 Cologne]</i></p>

<p>
GR: It makes me nervous that someone at some point decided to not add "non-<code>volatile</code>".<br/> 
AM: That was over ten years ago. It was a deliberate, minuted choice to support <code>volatile</code>. We are now reversing that decision. 
It would be good to poll our vendors, none of which are in the room. This is a bit more work than we expect of a P0 issue.<br/> 
VV: libstdc++ and libc++ seem to support <code>volatile</code> template parameters for the standard allocator.<br/> 
AM: To clarify, the proposed resolution here would remove the requirement to support <code>volatile</code>. Implementations could still 
choose to support <code>volatile</code>.<br/>
DK: I'm happy to drop this and open a new issue in regard to the <code>destroy</code> member specification.<br/>
AM: I just think this is harder than a P0. Let's reprioritize.
</p>

<p><i>[2015-04-01 Daniel comments]</i></p>

<p>
The less controversial part of the issue related to constraints imposed on <code>destroy</code> has be handed over to the new 
issue <a href="lwg-defects.html#2470" title="Allocator's destroy function should be allowed to fail to instantiate (Status: C++17)">2470</a><sup><a href="https://cplusplus.github.io/LWG/issue2470" title="Latest snapshot">(i)</a></sup>.
</p>

<p><i>[2015-05-06 Lenexa: Move to Ready]</i></p>



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

<ol>
<li><p>Change 16.4.4.6 <a href="https://wg21.link/allocator.requirements">[allocator.requirements]</a>, Table 27 &mdash; "Descriptive variable definitions", as indicated:</p>
<blockquote>
<table border="1">
<caption>Table 27 &mdash; Descriptive variable definitions</caption>
<tr>
<th>Variable</th>
<th>Definition</th>
</tr>

<tr>
<td>
<code>T, U, C</code>
</td>
<td>
any <del>non-const</del><ins><i>cv</i>-unqualified</ins> object type (3.9)
</td>
</tr>

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

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





</body>
</html>
