<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2969: polymorphic_allocator::construct() shouldn't pass resource()</title>
<meta property="og:title" content="Issue 2969: polymorphic_allocator::construct() shouldn't pass resource()">
<meta property="og:description" content="C++ library issue. Status: C++20">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2969.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="2969"><a href="lwg-defects.html#2969">2969</a>. <code>polymorphic_allocator::construct()</code> shouldn't pass <code>resource()</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#C++20">C++20</a>
 <b>Submitter:</b> Pablo Halpern <b>Opened:</b> 2017-05-30 <b>Last modified:</b> 2021-02-25</p>
<p><b>Priority: </b>2
</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#C++20">C++20</a> status.</p>
<p><b>Discussion:</b></p>
<p>
Section 20.5.3.3 <a href="https://wg21.link/mem.poly.allocator.mem">[mem.poly.allocator.mem]</a> defines the effect of <code>polymorphic_allocator&lt;T&gt;::construct</code> as:
</p>
<blockquote>
<p>
<i>Effects:</i> Construct a <code>T</code> object in the storage whose address is represented by <code>p</code> by uses-allocator
construction with allocator <code>resource()</code> and constructor arguments <code>std::forward&lt;Args&gt;(args)...</code>.
</p>
</blockquote>
<p>
The use of <code>resource()</code> is a hold-over from the LFTS, which contains a modified definition of uses-allocator construction. This revised definition was not carried over into the C++17 WP when allocator_resource and polymorphic_allocator were moved over.
</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<p>This wording is relative to <a href="https://wg21.link/n4659">N4659</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 T, class... Args&gt;
  void construct(T* p, Args&amp;&amp;... args);
</pre>
<blockquote>
<p>
-5- <i>Requires:</i> Uses-allocator construction of <code>T</code> with allocator <code><del>resource()</del><ins>*this</ins></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> 
is well-formed. [<i>Note:</i> Uses-allocator construction is always well formed for types that do not use 
allocators. &mdash; <i>end note</i>]
<p/>
-6- <i>Effects:</i> Construct a <code>T</code> object in the storage whose address is represented by <code>p</code> by 
uses-allocator construction with allocator <code><del>resource()</del><ins>*this</ins></code> and constructor arguments 
<code>std::forward&lt;Args&gt;(args)...</code>.
<p/>
-7- <i>Throws:</i> Nothing unless the constructor for <code>T</code> throws.
</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>
-8- [<i>Note:</i> This method and the <code>construct</code> methods that follow are overloads for piecewise construction
of pairs (22.3.2 <a href="https://wg21.link/pairs.pair">[pairs.pair]</a>). &mdash; <i>end note</i>]
<p/>
-9- <i>Effects:</i> Let <code>xprime</code> be a <code>tuple</code> constructed from <code>x</code> according to the appropriate rule 
from the following list. [<i>Note:</i> The following description can be summarized as constructing a 
<code>pair&lt;T1, T2&gt;</code> object in the storage whose address is represented by <code>p</code>, as if by separate 
uses-allocator construction with allocator <code><del>resource()</del><ins>*this</ins></code> 
(20.2.8.2 <a href="https://wg21.link/allocator.uses.construction">[allocator.uses.construction]</a>) of <code>p-&gt;first</code> using the elements of <code>x</code> and 
<code>p-&gt;second</code> using the elements of <code>y</code>. &mdash; <i>end note</i>]
<p/>
[&hellip;]
</p>
</blockquote>
</blockquote>
</li>
</ol>
</blockquote>

<p><i>[2017-06-12, Pablo comments]</i></p>

<p>
The current description is correct and does not depend on changes to uses-allocator construction. It relies on the fact 
that <code>memory_resource*</code> is convertible to <code>polymorphic_allocator</code>.
</p>

<p><i>[2017-06-13, Tim Song reopens]</i></p>

<p>
While it is true that <code>memory_resource*</code> is convertible to <code>polymorphic_allocator</code>,
uses-allocator construction still requires allocators, and a
<code>memory_resource*</code> isn't an allocator.
<p/>
To take a concrete example from the current WP, a <code>pmr::vector&lt;std::promise&lt;int&gt;&gt;</code>, as specified, 
will be attempting to uses-allocator construct a <code>promise&lt;int&gt;</code> with a <code>memory_resource*</code>, but
<code>std::promise</code>'s allocator-taking constructor expects something that satisfies the allocator requirements, 
rather than a <code>memory_resource*</code>.
</p>

<p><i>[2017-06-13, Daniel and Tim restore and improve the previously proposed wording]</i></p>

<p>
</p>

<p><i>[2017-07 Toronto Monday issue prioritization]</i></p>

<p>Priority 2; Dietmar to check the P/R before Albuquerque.</p>

<p><i>[2017-11 Albuquerque Wednesday issue processing]</i></p>

<p>Move to Ready.</p>
<p><i>[2018-3-17 Adopted in Jacksonville]</i></p>



<p id="res-2969"><b>Proposed resolution:</b></p>
<p>This wording is relative to <a href="https://wg21.link/n4659">N4659</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 T, class... Args&gt;
  void construct(T* p, Args&amp;&amp;... args);
</pre>
<blockquote>
<p>
-5- <i>Requires:</i> Uses-allocator construction of <code>T</code> with allocator <code><del>resource()</del><ins>*this</ins></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> 
is well-formed. [<i>Note:</i> Uses-allocator construction is always well formed for types that do not use 
allocators. &mdash; <i>end note</i>]
<p/>
-6- <i>Effects:</i> Construct a <code>T</code> object in the storage whose address is represented by <code>p</code> by 
uses-allocator construction with allocator <code><del>resource()</del><ins>*this</ins></code> and constructor arguments 
<code>std::forward&lt;Args&gt;(args)...</code>.
<p/>
-7- <i>Throws:</i> Nothing unless the constructor for <code>T</code> throws.
</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>
-8- [<i>Note:</i> This method and the <code>construct</code> methods that follow are overloads for piecewise construction
of pairs (22.3.2 <a href="https://wg21.link/pairs.pair">[pairs.pair]</a>). &mdash; <i>end note</i>]
<p/>
-9- <i>Effects:</i> Let <code>xprime</code> be a <code>tuple</code> constructed from <code>x</code> according to the appropriate rule 
from the following list. [<i>Note:</i> The following description can be summarized as constructing a 
<code>pair&lt;T1, T2&gt;</code> object in the storage whose address is represented by <code>p</code>, as if by separate 
uses-allocator construction with allocator <code><del>resource()</del><ins>*this</ins></code> 
(20.2.8.2 <a href="https://wg21.link/allocator.uses.construction">[allocator.uses.construction]</a>) of <code>p-&gt;first</code> using the elements of <code>x</code> and 
<code>p-&gt;second</code> using the elements of <code>y</code>. &mdash; <i>end note</i>]
</p>
<ol style="list-style-type: none">
<li><p>(9.1) &mdash; If <code>uses_allocator_v&lt;T1,<del>memory_resource*</del><ins>polymorphic_allocator</ins>&gt;</code> is <code>false</code>
and <code>is_constructible_v&lt;T1,Args1...&gt;</code> is <code>true</code>, then <code>xprime</code> is <code>x</code>.</p></li>
<li><p>(9.2) &mdash; Otherwise, if <code>uses_allocator_v&lt;T1,<del>memory_resource*</del><ins>polymorphic_allocator</ins>&gt;</code> is <code>true</code>
and <code>is_constructible_v&lt;T1,allocator_arg_t,<del>memory_resource*</del><ins>polymorphic_allocator</ins>,Args1...&gt;</code> is <code>true</code>, then 
<code>xprime</code> is <code>tuple_cat(make_tuple(allocator_arg, <del>resource()</del><ins>*this</ins>), 
std::move(x))</code>.</p></li>
<li><p>(9.3) &mdash; Otherwise, if <code>uses_allocator_v&lt;T1,<del>memory_resource*</del><ins>polymorphic_allocator</ins>&gt;</code> is <code>true</code> and 
<code>is_constructible_v&lt;T1,Args1...,<del>memory_resource*</del><ins>polymorphic_allocator</ins>&gt;</code> is <code>true</code>, then <code>xprime</code> is 
<code>tuple_cat(std::move(x), make_tuple(<del>resource()</del><ins>*this</ins>))</code>.</p></li>
<li><p>(9.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>(9.5) &mdash; If <code>uses_allocator_v&lt;T2,<del>memory_resource*</del><ins>polymorphic_allocator</ins>&gt;</code> is <code>false</code>
and <code>is_constructible_v&lt;T2,Args2...&gt;</code> is <code>true</code>, then <code>yprime</code> is <code>y</code>.</p></li>
<li><p>(9.6) &mdash; Otherwise, if <code>uses_allocator_v&lt;T2,<del>memory_resource*</del><ins>polymorphic_allocator</ins>&gt;</code> is <code>true</code> and 
<code>is_constructible_v&lt;T2,allocator_arg_t,<del>memory_resource*</del><ins>polymorphic_allocator</ins>,Args2...&gt;</code> is <code>true</code>, then <code>yprime</code> 
is <code>tuple_cat(make_tuple(allocator_arg, <del>resource()</del><ins>*this</ins>), std::move(y))</code>.</p></li>
<li><p>(9.7) &mdash; Otherwise, if <code>uses_allocator_v&lt;T2,<del>memory_resource*</del><ins>polymorphic_allocator</ins>&gt;</code> is <code>true</code> and 
<code>is_constructible_v&lt;T2,Args2...,<del>memory_resource*</del><ins>polymorphic_allocator</ins>&gt;</code> is <code>true</code>,
then <code>yprime</code> is <code>tuple_cat(std::move(y), make_tuple(<del>resource()</del><ins>*this</ins>))</code>.</p></li>
<li><p>(9.8) &mdash; Otherwise the program is ill formed.</p></li>
</ol>
</blockquote>
</blockquote>
</li>
</ol>






</body>
</html>
