<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2586: Wrong value category used in scoped_allocator_adaptor::construct()</title>
<meta property="og:title" content="Issue 2586: Wrong value category used in scoped_allocator_adaptor::construct()">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2586.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++17">C++17</a> status.</em></p>
<h3 id="2586"><a href="lwg-defects.html#2586">2586</a>. Wrong value category used in <code>scoped_allocator_adaptor::construct()</code></h3>
<p><b>Section:</b> 20.6.4 <a href="https://wg21.link/allocator.adaptor.members">[allocator.adaptor.members]</a>, 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++17">C++17</a>
 <b>Submitter:</b> Jonathan Wakely <b>Opened:</b> 2016-01-15 <b>Last modified:</b> 2017-07-30</p>
<p><b>Priority: </b>0
</p>
<p><b>View all other</b> <a href="lwg-index.html#allocator.adaptor.members">issues</a> in [allocator.adaptor.members].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++17">C++17</a> status.</p>
<p><b>Discussion:</b></p>
<p>
20.6.4 <a href="https://wg21.link/allocator.adaptor.members">[allocator.adaptor.members]</a> p9 says that the <code>is_constructible</code>
tests are done using <code>inner_allocator_type</code>, which checks for
construction from an rvalue, but then the constructor is passed
<code>inner_allocator()</code> which returns a non-<code>const</code> lvalue reference. The
value categories should be consistent, otherwise this fails to
compile:
</p>
<blockquote><pre>
#include &lt;memory&gt;
#include &lt;scoped_allocator&gt;

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

int main() {
  std::scoped_allocator_adaptor&lt;std::allocator&lt;X&gt;&gt; sa;
  sa.construct(sa.allocate(1));
}
</pre></blockquote>
<p>
<code>uses_allocator&lt;X, decltype(sa)::inner_allocator_type&gt;></code> is true, because
it can be constructed from an rvalue of the allocator type, so bullet (9.1) doesn't apply.
<p/>
<code>is_constructible&lt;X, allocator_arg_t, decltype(sa)::inner_allocator_type></code> 
is true, so bullet (9.2) applies.
That means we try to construct the object passing it
<code>sa.inner_allocator()</code> which is an lvalue reference, so it fails.
<p/>
The <code>is_constructible</code> checks should use an lvalue reference, as that's
what's actually going to be used.
<p/>
I don't think the same problem exists in the related wording in
20.2.8.2 <a href="https://wg21.link/allocator.uses.construction">[allocator.uses.construction]</a> if we assume that the value categories
of <code>v1, v2, ..., vN</code> and <code>alloc</code> are meant to be preserved, so that the
<code>is_constructible</code> traits and the initialization expressions match.
However, it does say "an allocator <code>alloc</code> of type <code>Alloc</code>" and if <code>Alloc</code>
is an reference type then it's not an allocator, so I suggest a small tweak there too.
</p>

<p><i>[2016-02, Issues Telecon]</i></p>

<p>
Strike first paragraph of PR, and move to Tentatively Ready.
</p>

<strong>Original Resolution [SUPERSEDED]:</strong>
<blockquote class="note">
<ol>
<li><p>Change 20.2.8.2 <a href="https://wg21.link/allocator.uses.construction">[allocator.uses.construction]</a> p1:</p>
<blockquote>
<p>
-1- Uses-allocator construction with allocator <code>Alloc</code> refers to the construction of an object <code>obj</code> 
of type <code>T</code>, using constructor arguments <code>v1, v2, ..., vN</code> of types <code>V1, V2, ..., VN</code>, respectively, 
and an allocator <ins>(or reference to an allocator)</ins> <code>alloc</code> of type <code>Alloc</code>, according to the 
following rules:
</p>
</blockquote>
</li>

<li><p>Change the 2nd and 3rd bullets in 20.6.4 <a href="https://wg21.link/allocator.adaptor.members">[allocator.adaptor.members]</a> p9 to add two lvalue-references:</p>

<blockquote>
<ol style="list-style-type: none">
<li><p>(9.2) &mdash; Otherwise, if <code>uses_allocator&lt;T, inner_allocator_type&gt;::value</code> is <code>true</code> and 
<code>is_constructible&lt;T, allocator_arg_t, inner_allocator_type<ins>&amp;</ins>, Args...&gt;::value</code> is <code>true</code>, calls 
<code><i>OUTERMOST_ALLOC_TRAITS</i>(*this)::construct(<i>OUTERMOST</i>(*this), p, allocator_arg, inner_allocator(), 
std::forward&lt;Args&gt;(args)...)</code>.</p></li>
<li><p>(9.3) &mdash; Otherwise, if <code>uses_allocator&lt;T, inner_allocator_type&gt;::value</code> is <code>true</code> and 
<code>is_constructible&lt;T, Args..., inner_allocator_type<ins>&amp;</ins>&gt;::value</code> is <code>true</code>, calls 
<code><i>OUTERMOST_ALLOC_TRAITS</i>(*this)::construct(<i>OUTERMOST</i>(*this), p, std::forward&lt;Args&gt;(args)...,
inner_allocator())</code>.</p></li>
</ol>
</blockquote>
</li>

<li><p>Change the 2nd, 3rd, 6th, and 7th bullets in 20.6.4 <a href="https://wg21.link/allocator.adaptor.members">[allocator.adaptor.members]</a> p11 to
add four lvalue-references:</p>

<blockquote>
<ol style="list-style-type: none">
<li><p>(11.2) &mdash; Otherwise, if <code>uses_allocator&lt;T1, inner_allocator_type&gt;::value</code> is <code>true</code> and 
<code>is_constructible&lt;T1, allocator_arg_t, inner_allocator_type<ins>&amp;</ins>, Args1...&gt;::value</code> is <code>true</code>, 
then <code>xprime</code> is <code>tuple_cat(tuple&lt;allocator_arg_t, inner_allocator_type&amp;&gt;(allocator_arg, 
inner_allocator()), std::move(x))</code>.</p></li>
<li><p>(11.3) &mdash; Otherwise, if <code>uses_allocator&lt;T1, inner_allocator_type&gt;::value</code> is <code>true</code> and 
<code>is_constructible&lt;T1, Args1..., inner_allocator_type<ins>&amp;</ins>&gt;::value</code> is <code>true</code>, then 
<code>xprime</code> is <code>tuple_cat(std::move(x), tuple&lt;inner_allocator_type&amp;&gt;(inner_allocator()))</code>.</p></li>
<li><p>[&hellip;]</p></li>
<li><p>(11.6) &mdash; Otherwise, if <code>uses_allocator&lt;T2, inner_allocator_type&gt;::value</code> is <code>true</code> and 
<code>is_constructible&lt;T2, allocator_arg_t, inner_allocator_type<ins>&amp;</ins>, Args2...&gt;::value</code> is <code>true</code>, 
then <code>yprime</code> is <code>tuple_cat(tuple&lt;allocator_arg_t, inner_allocator_type&amp;&gt;(allocator_arg, 
inner_allocator()), std::move(y))</code>.</p></li>
<li><p>(11.7) &mdash; Otherwise, if <code>uses_allocator&lt;T2, inner_allocator_type&gt;::value</code> is <code>true</code> and 
<code>is_constructible&lt;T2, Args2..., inner_allocator_type<ins>&amp;</ins>&gt;::value</code> is <code>true</code>, then 
<code>yprime</code> is <code>tuple_cat(std::move(y), tuple&lt;inner_allocator_type&amp;&gt;(inner_allocator()))</code>.</p></li>
</ol>
</blockquote>
</li>
</ol>
</blockquote>

<p><i>[2016-02, Issues Telecon]</i></p>

<p>
P0; move to Tentatively Ready.
</p>


<p id="res-2586"><b>Proposed resolution:</b></p>
<p>
This wording is relative to N4567.
</p>

<ol>
<li><p>Change the 2nd and 3rd bullets in 20.6.4 <a href="https://wg21.link/allocator.adaptor.members">[allocator.adaptor.members]</a> p9 to add two lvalue-references:</p>

<blockquote>
<ol style="list-style-type: none">
<li><p>(9.2) &mdash; Otherwise, if <code>uses_allocator&lt;T, inner_allocator_type&gt;::value</code> is <code>true</code> and 
<code>is_constructible&lt;T, allocator_arg_t, inner_allocator_type<ins>&amp;</ins>, Args...&gt;::value</code> is <code>true</code>, calls 
<code><i>OUTERMOST_ALLOC_TRAITS</i>(*this)::construct(<i>OUTERMOST</i>(*this), p, allocator_arg, inner_allocator(), 
std::forward&lt;Args&gt;(args)...)</code>.</p></li>
<li><p>(9.3) &mdash; Otherwise, if <code>uses_allocator&lt;T, inner_allocator_type&gt;::value</code> is <code>true</code> and 
<code>is_constructible&lt;T, Args..., inner_allocator_type<ins>&amp;</ins>&gt;::value</code> is <code>true</code>, calls 
<code><i>OUTERMOST_ALLOC_TRAITS</i>(*this)::construct(<i>OUTERMOST</i>(*this), p, std::forward&lt;Args&gt;(args)...,
inner_allocator())</code>.</p></li>
</ol>
</blockquote>
</li>

<li><p>Change the 2nd, 3rd, 6th, and 7th bullets in 20.6.4 <a href="https://wg21.link/allocator.adaptor.members">[allocator.adaptor.members]</a> p11 to
add four lvalue-references:</p>

<blockquote>
<ol style="list-style-type: none">
<li><p>(11.2) &mdash; Otherwise, if <code>uses_allocator&lt;T1, inner_allocator_type&gt;::value</code> is <code>true</code> and 
<code>is_constructible&lt;T1, allocator_arg_t, inner_allocator_type<ins>&amp;</ins>, Args1...&gt;::value</code> is <code>true</code>, 
then <code>xprime</code> is <code>tuple_cat(tuple&lt;allocator_arg_t, inner_allocator_type&amp;&gt;(allocator_arg, 
inner_allocator()), std::move(x))</code>.</p></li>
<li><p>(11.3) &mdash; Otherwise, if <code>uses_allocator&lt;T1, inner_allocator_type&gt;::value</code> is <code>true</code> and 
<code>is_constructible&lt;T1, Args1..., inner_allocator_type<ins>&amp;</ins>&gt;::value</code> is <code>true</code>, then 
<code>xprime</code> is <code>tuple_cat(std::move(x), tuple&lt;inner_allocator_type&amp;&gt;(inner_allocator()))</code>.</p></li>
<li><p>[&hellip;]</p></li>
<li><p>(11.6) &mdash; Otherwise, if <code>uses_allocator&lt;T2, inner_allocator_type&gt;::value</code> is <code>true</code> and 
<code>is_constructible&lt;T2, allocator_arg_t, inner_allocator_type<ins>&amp;</ins>, Args2...&gt;::value</code> is <code>true</code>, 
then <code>yprime</code> is <code>tuple_cat(tuple&lt;allocator_arg_t, inner_allocator_type&amp;&gt;(allocator_arg, 
inner_allocator()), std::move(y))</code>.</p></li>
<li><p>(11.7) &mdash; Otherwise, if <code>uses_allocator&lt;T2, inner_allocator_type&gt;::value</code> is <code>true</code> and 
<code>is_constructible&lt;T2, Args2..., inner_allocator_type<ins>&amp;</ins>&gt;::value</code> is <code>true</code>, then 
<code>yprime</code> is <code>tuple_cat(std::move(y), tuple&lt;inner_allocator_type&amp;&gt;(inner_allocator()))</code>.</p></li>
</ol>
</blockquote>
</li>
</ol>





</body>
</html>
