<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3187: P0591R4 reverted DR 2586 fixes to scoped_allocator_adaptor::construct()</title>
<meta property="og:title" content="Issue 3187: P0591R4 reverted DR 2586 fixes to scoped_allocator_adaptor::construct()">
<meta property="og:description" content="C++ library issue. Status: C++20">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3187.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="3187"><a href="lwg-defects.html#3187">3187</a>. <a href="https://wg21.link/p0591r4">P0591R4</a> reverted DR 2586 fixes to <code>scoped_allocator_adaptor::construct()</code></h3>
<p><b>Section:</b> 20.2.8.2 <a href="https://wg21.link/allocator.uses.construction">[allocator.uses.construction]</a> <b>Status:</b> <a href="lwg-active.html#C++20">C++20</a>
 <b>Submitter:</b> Jonathan Wakely <b>Opened:</b> 2019-02-14 <b>Last modified:</b> 2021-02-25</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View other</b> <a href="lwg-index-open.html#allocator.uses.construction">active issues</a> in [allocator.uses.construction].</p>
<p><b>View all other</b> <a href="lwg-index.html#allocator.uses.construction">issues</a> in [allocator.uses.construction].</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>
<a href="lwg-defects.html#2586" title="Wrong value category used in scoped_allocator_adaptor::construct() (Status: C++17)">2586</a><sup><a href="https://cplusplus.github.io/LWG/issue2586" title="Latest snapshot">(i)</a></sup> fixed the value category in the uses-allocator checks done by <code>scoped_allocator_adaptor</code>. 
When we made that use <code>uses_allocator_construction_args</code> we reintroduced the problem, because that 
function has the same bug.
</p>
<blockquote><pre>
#include &lt;memory&gt;

struct X {
  using allocator_type = std::allocator&lt;X&gt;;
  X(std::allocator_arg_t, allocator_type&amp;&amp;) { }
  X(const allocator_type&amp;) { }
};

int main() {
  std::allocator&lt;X&gt; a;
  std::make_obj_using_allocator&lt;X&gt;(a);
}
</pre></blockquote>
<p>
This will fail to compile, because <code>uses_allocator_construction_args</code> will check <code>is_constructible</code> 
using an rvalue allocator, but then return <code>tuple&lt;allocator_arg_t, const allocator&lt;X&gt;&amp;&gt;</code> 
containing an lvalue allocator. Those args cannot be used to construct an <code>X</code>.
</p>

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

<p>Status to Ready</p>


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

<ol>
<li><p>Change 20.2.8.2 <a href="https://wg21.link/allocator.uses.construction">[allocator.uses.construction]</a> as indicated:</p>

<blockquote class="note">
<p>
[<i>Drafting Note:</i> Arguably the <code>uses_allocator</code> specialization should also use <code>const Alloc&amp;</code> 
but in practice that doesn't matter, except for even more contrived cases than the very contrived example above.]
</p>
</blockquote>

<blockquote>
<pre>
template &lt;class T, class Alloc, class... Args&gt;
  auto uses_allocator_construction_args(const Alloc&amp; alloc, Args&amp;&amp;... args) -&gt; <i>see below</i>;
</pre>
<blockquote>
<p>
[&hellip;]
<p/>
-5- <i>Returns:</i> A <code>tuple</code> value determined as follows:
<ol>
<li><p>(5.1) &mdash; If <code>uses_allocator_v&lt;T, Alloc&gt;</code> is <code>false</code> and 
<code>is_constructible_v&lt;T, Args...&gt;</code> is <code>true</code>, return 
<code>forward_as_tuple(std::forward&lt;Args&gt;(args)...)</code>.</p></li>
<li><p>(5.2) &mdash; Otherwise, if <code>uses_allocator_v&lt;T, Alloc&gt;</code> is <code>true</code> and <code>is_constructible_v&lt;T, 
allocator_arg_t, <ins>const</ins> Alloc<ins>&amp;</ins>, Args...&gt;</code> is <code>true</code>, return
<blockquote><pre>
tuple&lt;allocator_arg_t, const Alloc&amp;, Args&amp;&amp;...&gt;(
  allocator_arg, alloc, std::forward&lt;Args&gt;(args)...)
</pre></blockquote>
</p></li>
<li><p>(5.3) &mdash; Otherwise, if <code>uses_allocator_v&lt;T, Alloc&gt;</code> is <code>true</code> and <code>is_constructible_v&lt;T, 
Args..., <ins>const</ins> Alloc<ins>&amp;</ins>&gt;</code> is <code>true</code>, return 
<code>forward_as_tuple(std::forward&lt;Args&gt;(args)..., alloc)</code>.</p></li>
<li><p>(5.4) &mdash; Otherwise, the program is ill-formed.</p></li>
</ol>
<p/>
[&hellip;]
</p>
</blockquote>
</blockquote>
</li>

</ol>




</body>
</html>
