<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3113: polymorphic_allocator::construct() should more closely match scoped_allocator_adaptor::construct()</title>
<meta property="og:title" content="Issue 3113: polymorphic_allocator::construct() should more closely match scoped_allocator_adaptor::construct()">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3113.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#Resolved">Resolved</a> status.</em></p>
<h3 id="3113"><a href="lwg-defects.html#3113">3113</a>. <code>polymorphic_allocator::construct()</code> should more closely match <code>scoped_allocator_adaptor::construct()</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#Resolved">Resolved</a>
 <b>Submitter:</b> Arthur O'Dwyer <b>Opened:</b> 2018-05-14 <b>Last modified:</b> 2020-09-06</p>
<p><b>Priority: </b>3
</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#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>
<p>
Based on my new understanding of how <code>uses_allocator</code> and <code>is_constructible</code> are supposed to play together, 
I think there was a minor defect in the resolution of LWG <a href="lwg-defects.html#2969" title="polymorphic_allocator::construct() shouldn't pass resource() (Status: C++20)">2969</a><sup><a href="https://cplusplus.github.io/LWG/issue2969" title="Latest snapshot">(i)</a></sup> "<code>polymorphic_allocator::construct()</code> 
shouldn't pass <code>resource()</code>".
<p/>
The calls to <code>is_constructible</code> in 20.5.3.3 <a href="https://wg21.link/mem.poly.allocator.mem">[mem.poly.allocator.mem]</a> (10.2), which were added to resolve LWG 
<a href="lwg-defects.html#2969" title="polymorphic_allocator::construct() shouldn't pass resource() (Status: C++20)">2969</a><sup><a href="https://cplusplus.github.io/LWG/issue2969" title="Latest snapshot">(i)</a></sup>, are missing an lvalue-qualification to match the lvalue-qualification of the parallel calls in 
 [llocator.adaptor.member] (9.2).
<p/>
The latter talks about constructibility from <code>inner_allocator_type&amp;</code>; the former (after LWG 2969) talks about 
constructibility from <code>polymorphic_allocator</code> with no ref-qualification. But since we are perfect-forwarding 
<code>*this</code> through a tuple of references, we definitely <em>are</em> going to try to construct the target object from 
a <code>polymorphic_allocator&amp;</code> and not from a <code>polymorphic_allocator</code>. I believe that the wording in
20.5.3.3 <a href="https://wg21.link/mem.poly.allocator.mem">[mem.poly.allocator.mem]</a> (10.2) needs to be updated to make the program ill-formed in cases where
that construction is going to fail.
<p/>
Orthogonally, I believe we need additional <code>std::move</code>'s in the sentence following 20.5.3.3 <a href="https://wg21.link/mem.poly.allocator.mem">[mem.poly.allocator.mem]</a> (10.8)
for two reasons:
</p>
<ul>
<li><p>We don't want to copy-construct the user's arguments that came in
  by-value as part of <code>x</code> and/or <code>y</code>.</p></li>
<li><p>The value category of the argument to <code>pair</code>'s constructor is currently
  unspecified; it could reasonably be either an xvalue or a prvalue. Adding the <code>std::move</code> makes it clearer 
  that we really want it to be an xvalue.</p></li>
</ul>

<p><i>[2018-06-18 after reflector discussion]</i></p>

<p>Priority set to 3</p>
<p><i>[2019-02; Kona Wednesday night issue processing]</i></p>

<p>This was resolved by the adoption of <a href="https://wg21.link/P0591">P0591</a> in San Diego.</p>


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

<ol>
<li><p>Edit 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 T1, class T2, class... Args1, class... Args2&gt;
  void construct(pair&lt;T1, T2&gt;* p, piecewise_construct_t, tuple&lt;Args1...&gt; x, tuple&lt;Args2...&gt; y);
</pre>
<blockquote>
<p>
-9- [&hellip;]
<p/>
-10- <i>Effects::</i> [&hellip;]
</p>
<ol style="list-style-type: none">
<li><p>(10.1) &mdash; [&hellip;]</p></li>
<li><p>(10.2) &mdash; Otherwise, if <code>uses_allocator_v&lt;T1,polymorphic_allocator&gt;</code> is <code>true</code>
and <code>is_constructible_v&lt;T1, allocator_arg_t, polymorphic_allocator<ins>&amp;</ins>, Args1...&gt;</code> is <code>true</code>,
then <code>xprime</code> is <code>tuple_cat(<del>make_tuple</del><ins>tuple&lt;allocator_arg_t, 
polymorphic_allocator&amp;&gt;</ins>(allocator_arg, *this), std::move(x))</code>.</p></li>
<li><p>(10.3) &mdash; Otherwise, if <code>uses_allocator_v&lt;T1, polymorphic_allocator&gt;</code> is <code>true</code>
and <code>is_constructible_v&lt;T1, Args1..., polymorphic_allocator<ins>&amp;</ins>&gt;</code> is <code>true</code>, then 
<code>xprime</code> is <code>tuple_cat(std::move(x), <del>make_tuple</del><ins>tuple&lt;polymorphic_allocator&amp;&gt;</ins>(*this))</code>.</p></li>
<li><p>(10.4) &mdash; Otherwise the program is ill formed.</p></li>
</ol>
<p>
Let <code>yprime</code> be a tuple constructed from <code>y</code> according to the appropriate rule from the following list:
</p>
<ol style="list-style-type: none">
<li><p>(10.5) &mdash; [&hellip;]</p></li>
<li><p>(10.6) &mdash; Otherwise, if <code>uses_allocator_v&lt;T2, polymorphic_allocator&gt;</code> is <code>true</code>
and <code>is_constructible_v&lt;T2, allocator_arg_t, polymorphic_allocator<ins>&amp;</ins>, Args2...&gt;</code> is <code>true</code>,
then <code>yprime</code> is <code>tuple_cat(<del>make_tuple</del><ins>tuple&lt;allocator_arg_t, 
polymorphic_allocator&amp;&gt;</ins>(allocator_arg, *this), std::move(y))</code>.</p></li>
<li><p>(10.7) &mdash; Otherwise, if <code>uses_allocator_v&lt;T2, polymorphic_allocator&gt;</code> is <code>true</code>
and <code>is_constructible_v&lt;T2, Args2..., polymorphic_allocator<ins>&amp;</ins>&gt;</code> is <code>true</code>, then <code>yprime</code> 
is <code>tuple_cat(std::move(y), <del>make_tuple</del><ins>tuple&lt;polymorphic_allocator&amp;&gt;</ins>(*this))</code>.</p></li>
<li><p>(10.8) &mdash; Otherwise the program is ill formed.</p></li>
</ol>
<p>
Then, using <code>piecewise_construct</code>, <code><ins>std::move(</ins>xprime<ins>)</ins></code>, and 
<code><ins>std::move(</ins>yprime<ins>)</ins></code> as the constructor arguments, this function
constructs a <code>pair&lt;T1, T2&gt;</code> object in the storage whose address is represented by <code>p</code>.
</p>
</blockquote>
</blockquote>
</li>

</ol>





</body>
</html>
