<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3916: allocator, polymorphic_allocator, and containers should forbid cv-qualified types</title>
<meta property="og:title" content="Issue 3916: allocator, polymorphic_allocator, and containers should forbid cv-qualified types">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3916.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#New">New</a> status.</em></p>
<h3 id="3916"><a href="lwg-active.html#3916">3916</a>. <code>allocator</code>, <code>polymorphic_allocator</code>, and containers should forbid <i>cv</i>-qualified types</h3>
<p><b>Section:</b> 20.2.10 <a href="https://wg21.link/default.allocator">[default.allocator]</a>, 20.5.3.1 <a href="https://wg21.link/mem.poly.allocator.class.general">[mem.poly.allocator.class.general]</a>, 23.2 <a href="https://wg21.link/container.requirements">[container.requirements]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
 <b>Submitter:</b> Stephan T. Lavavej <b>Opened:</b> 2023-04-02 <b>Last modified:</b> 2023-05-24</p>
<p><b>Priority: </b>3
</p>
<p><b>View other</b> <a href="lwg-index-open.html#default.allocator">active issues</a> in [default.allocator].</p>
<p><b>View all other</b> <a href="lwg-index.html#default.allocator">issues</a> in [default.allocator].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
<p><b>Discussion:</b></p>
<p>
LWG <a href="lwg-defects.html#2447" title="Allocators and volatile-qualified value types (Status: C++17)">2447</a><sup><a href="https://cplusplus.github.io/LWG/issue2447" title="Latest snapshot">(i)</a></sup> adjusted what is now <a href="https://wg21.link/N4944" title=" Working Draft, Standard for Programming Language C++">N4944</a> 16.4.4.6.1 <a href="https://wg21.link/allocator.requirements.general">[allocator.requirements.general]</a>/2.1 
so that the <i>Cpp17Allocator</i> requirements are specified for <i>cv</i>-unqualified object types only.
<p/>
However, nothing in 20.2.10 <a href="https://wg21.link/default.allocator">[default.allocator]</a> restricts what <code>T</code> in <code>allocator&lt;T&gt;</code> can be, 
except where 20.2.10.2 <a href="https://wg21.link/allocator.members">[allocator.members]</a>/2 and /6 require it to be complete for <code>allocate()</code> and 
<code>allocate_at_least()</code> (and by implication, for <code>deallocate()</code>). (Long ago, <code>allocator</code> had member functions 
whose signatures implied that <code>const</code>-qualified types were forbidden, but those signatures were deprecated and 
removed. This explains the phrasing of an MSVC static assertion.)
<p/>
20.5.3.1 <a href="https://wg21.link/mem.poly.allocator.class.general">[mem.poly.allocator.class.general]</a> says a bit more about <code>Tp</code> in <code>polymorphic_allocator&lt;Tp&gt;</code> 
but doesn't forbid anything. It says that if <code>Tp</code> is a <i>cv</i>-unqualified object type, then 
<code>polymorphic_allocator&lt;Tp&gt;</code> meets the <i>Cpp17Allocator</i> requirements and allocator completeness requirements, 
but that's all.
<p/>
There's some implementation variation here. libstdc++ and MSVC reject <code>allocator&lt;const int&gt;</code>. libc++ 
(as of LLVM 16) accepts it but this appears to have been an extension that they're trying to get rid of (their maintainers 
may be able to comment further; see 
<a href="https://github.com/llvm/llvm-project/commit/a54d028895c91da356a4aaf30e27a5a5b90dd313">llvm-project/commit/a54d028895c91da356a4aaf30e27a5a5b90dd313</a>).
These 3 implementations all reject <code>allocator&lt;volatile int&gt;</code>, <code>polymorphic_allocator&lt;const int&gt;</code>, 
and <code>polymorphic_allocator&lt;volatile int&gt;</code> with varying messages.
<p/>
The Standard should provide clarity here, by mandating that only <i>cv</i>-unqualified object types be given to <code>allocator</code>, 
<code>polymorphic_allocator</code>, and containers. (<code>allocator&lt;void&gt;</code> must also be allowed, of course. I forget 
if <code>polymorphic_allocator</code> is supposed to accept <code>void</code>.) This would simply Standardize existing/desired practice. 
While it may seem arcane, attempting to form <code>vector&lt;const T&gt;</code> is a common novice mistake &mdash; so common that 
MSVC had to add a <code>static_assert</code> to emit a clear error message.
</p>

<p><i>[2023-05-24; Reflector poll]</i></p>

<p>
Set priority to 3 after reflector poll.
</p>



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





</body>
</html>
