<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 4311: Can std::pmr::polymorphic_allocator::construct just call std::uninitialized_construct_using_allocator?</title>
<meta property="og:title" content="Issue 4311: Can std::pmr::polymorphic_allocator::construct just call std::uninitialized_construct_using_allocator?">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue4311.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="4311"><a href="lwg-active.html#4311">4311</a>. Can <code class='backtick'>std::pmr::polymorphic_allocator::construct</code> just call <code class='backtick'>std::uninitialized_construct_using_allocator</code>?</h3>
<p><b>Section:</b> 20.5.3.3 <a href="https://wg21.link/mem.poly.allocator.mem">[mem.poly.allocator.mem]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
 <b>Submitter:</b> Jiang An <b>Opened:</b> 2025-08-06 <b>Last modified:</b> 2025-08-16</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#mem.poly.allocator.mem">issues</a> in [mem.poly.allocator.mem].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
<p><b>Discussion:</b></p>
<p>
This is closely related to LWG <a href="lwg-closed.html#3901" title="Is uses-allocator construction of a cv-qualified object type still well-formed after LWG 3870? (Status: NAD)">3901</a><sup><a href="https://cplusplus.github.io/LWG/issue3901" title="Latest snapshot">(i)</a></sup> but only affects arguably pathological cases.
<p/>
Uses-allocator construction for <i>cv</i>-qualified types needs to be well-formed, but it's 
questionable to require <code class='backtick'>polymorphic_allocator::construct</code> to support constructing objects via 
pointer to a <i>cv</i>-qualified type. LWG <a href="lwg-defects.html#3870" title="Remove voidify (Status: C++23)">3870</a><sup><a href="https://cplusplus.github.io/LWG/issue3870" title="Latest snapshot">(i)</a></sup> banned such placement construction 
for <code class='backtick'>std::construct_at</code>, which is depended by <code class='backtick'>uninitialized_construct_using_allocator</code>.
<p/>
As a result, it seems non-conforming to just use <code class='backtick'>uninitialized_construct_using_allocator</code> in 
<code class='backtick'>polymorphic_allocator::construct</code> since C++20, because the latter is still required to handle 
<i>cv</i>-qualified target types. If the status quo is considered unintended and needed to be fixed, 
perhaps we can just respecify <code class='backtick'>polymorphic_allocator::construct</code> to use 
<code class='backtick'>uninitialized_construct_using_allocator</code>.
</p>


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

<blockquote class="note">
<p>
[<i>Drafting note</i>: The <i>Mandates</i>: element allows implementations not to add constraints even if 
<code class='backtick'>uninitialized_construct_using_allocator</code> is constrained in the future. The <i>Throws</i>: element is made 
redundant by "<i>Effects</i>: Equivalent to", and it's already wrong because the exception can be thrown 
by a conversion function.]
</p>
</blockquote>

<ol>

<li><p>Modify 20.5.3.3 <a href="https://wg21.link/mem.poly.allocator.mem">[mem.poly.allocator.mem]</a> as indicated:</p>

<blockquote>
<pre>
template&lt;class T, class... Args&gt;
  void construct(T* p, Args&amp;&amp;... args);
</pre>
<blockquote>
<p>
-14- <i>Mandates</i>: <del>Uses-allocator construction of <code class='backtick'>T</code> with allocator <code class='backtick'>*this</code> (see 
20.2.8.2 <a href="https://wg21.link/allocator.uses.construction">[allocator.uses.construction]</a>) and constructor arguments 
<code>std::forward&lt;Args&gt;(args)...</code></del><ins><code>uninitialized_construct_using_allocator(p, 
*this, std::forward&lt;Args&gt;(args)...)</code></ins> is well-formed.
<p/>
-15- <i>Effects</i>: <del>Constructs a <code class='backtick'>T</code> object in the storage whose address is represented by 
<code class='backtick'>p</code> by uses-allocator construction with allocator <code class='backtick'>*this</code> and constructor arguments 
<code>std::forward&lt;Args&gt;(args)...</code>.</del><ins>Equivalent to:</ins>
</p>
<blockquote><pre> 
<ins>uninitialized_construct_using_allocator(p, *this, std::forward&lt;Args&gt;(args)...);</ins>
</pre></blockquote>
<p>
<del>-16- <i>Throws</i>: Nothing unless the constructor for <code class='backtick'>T</code> throws.</del>
</p>
</blockquote>
</blockquote>

</li>

</ol>





</body>
</html>
