<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3192: &sect;[allocator.uses.construction] functions misbehave for const types</title>
<meta property="og:title" content="Issue 3192: &sect;[allocator.uses.construction] functions misbehave for const types">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3192.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="3192"><a href="lwg-active.html#3192">3192</a>. &sect;[allocator.uses.construction] functions misbehave for <code>const</code> types</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#New">New</a>
 <b>Submitter:</b> Jonathan Wakely <b>Opened:</b> 2019-02-28 <b>Last modified:</b> 2020-05-01</p>
<p><b>Priority: </b>3
</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#New">New</a> status.</p>
<p><b>Discussion:</b></p>
<p>
The new functions added by <a href="https://wg21.link/p0591r4">P0591R4</a> misbehave for <i>cv</i>-qualified types. 
A specialization <code>std::uses_allocator&lt;X, Alloc&gt;</code> will not match <code>const X</code>, so 
<code>std::uses_allocator_construction_args&lt;const X&gt;</code> will return a different result from 
<code>std::uses_allocator_construction_args&lt;X&gt;</code>. It makes no sense to construct <code>X</code> and <code>const X</code> 
differently, either the type wants to use an allocator or it doesn't. I think 
<code>std::uses_allocator_construction_args&lt;T&gt;</code> should remove <i>cv</i>-qualifiers before checking 
<code>uses_allocator</code>, so that it works consistently. 
<p/>
We could consider changing <code>std::make_obj_using_allocator</code> to also strip <i>cv</i>-qualifiers, but it's not 
necessary as C++17 guaranteed elision works even for prvalues of <code>const</code> types. We only need to make the 
construction args ignore <i>cv</i>-qualifiers. We don't want to make <i>cv</i>-qualified types ill-formed, because 
that would require users of uses-allocator construction to strip <i>cv</i>-qualifiers before using these functions, 
e.g. in cases like <code>std::tuple&lt;const int&gt; t(allocator_arg, alloc, 1);</code>
</p>

<p><i>[2019-03-15 Priority set to 3 after reflector discussion]</i></p>


<strong>Previous resolution [SUPERSEDED]:</strong>
<blockquote class="note">
<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>
<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>
-4- <i>Constraints:</i> <code>T</code> is not a specialization of <code>pair</code>.
<p/>
-5- <i>Returns:</i> A <code>tuple</code> value determined as follows<ins>, where <code>U</code> denotes the type 
<code>remove_cv_t&lt;T&gt;</code></ins>:
<ol style="list-style-type: none">
<li><p>(5.1) &mdash; If <code>uses_allocator_v&lt;<del>T</del><ins>U</ins>, 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;<del>T</del><ins>U</ins>, Alloc&gt;</code> is <code>true</code> and 
<code>is_constructible_v&lt;T, allocator_arg_t, Alloc, Args...&gt;</code> is <code>true</code>, return</p>
<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>
</li>
<li><p>(5.3) &mdash; Otherwise, if <code>uses_allocator_v&lt;<del>T</del><ins>U</ins>, Alloc&gt;</code> is <code>true</code> and 
<code>is_constructible_v&lt;T, Args..., Alloc&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>
</blockquote>
[&hellip;]
<pre>
template &lt;class T, class Alloc, class Tuple1, class Tuple2&gt;
  auto uses_allocator_construction_args(const Alloc&amp; alloc, piecewise_construct_t,
                                        Tuple1&amp;&amp; x, Tuple2&amp;&amp; y) -&gt; <i>see below</i>;
</pre>
<blockquote>
<p>
-6- <i>Constraints:</i> <code>T</code> is a specialization of <code>pair</code>.
<p/>
-7- <i>Effects:</i> For <code>T</code> specified as <ins>(possibly <code>const</code>)</ins> <code>pair&lt;T1, T2&gt;</code>, equivalent to:
<p/>
[&hellip;]
</p>
</blockquote>
<pre>
template &lt;class T, class Alloc, class... Args&gt;
  T* uninitialized_construct_using_allocator(T* p, const Alloc&amp; alloc, Args&amp;&amp;... args);
</pre>
<blockquote>
<p>
-17- <i>Effects:</i> Equivalent to:
</p>
<blockquote><pre>
return ::new(<del>static_cast&lt;void*&gt;</del><ins><i>voidify</i></ins>(<ins>*</ins>p))
  T(make_obj_using_allocator&lt;T&gt;(alloc, std::forward&lt;Args&gt;(args)...));
</pre></blockquote>
</blockquote>
</blockquote>
</li>
</ol>
</blockquote>

<p><i>[2020-05-01; Daniel syncs wording with recent working draft]</i></p>

<p>
The previously needed change for <code>uninitialized_construct_using_allocator</code> is no longer
required, because the reworded call to <code>construct_at</code> does do the right thing now.
</p>


<p id="res-3192"><b>Proposed resolution:</b></p>
<p>This wording is relative to <a href="https://wg21.link/n4861">N4861</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>
<pre>
template &lt;class T, class Alloc, class... Args&gt;
  constexpr auto uses_allocator_construction_args(const Alloc&amp; alloc, 
                                        Args&amp;&amp;... args) noexcept -&gt; <i>see below</i>;
</pre>
<blockquote>
<p>
-4- <i>Constraints:</i> <code>T</code> is not a specialization of <code>pair</code>.
<p/>
-5- <i>Returns:</i> A <code>tuple</code> value determined as follows<ins>, where <code>U</code> denotes the type 
<code>remove_cv_t&lt;T&gt;</code></ins>:
<ol style="list-style-type: none">
<li><p>(5.1) &mdash; If <code>uses_allocator_v&lt;<del>T</del><ins>U</ins>, 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;<del>T</del><ins>U</ins>, Alloc&gt;</code> is <code>true</code> and 
<code>is_constructible_v&lt;T, allocator_arg_t, const Alloc&amp;, Args...&gt;</code> is <code>true</code>, return</p>
<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>
</li>
<li><p>(5.3) &mdash; Otherwise, if <code>uses_allocator_v&lt;<del>T</del><ins>U</ins>, Alloc&gt;</code> is <code>true</code> and 
<code>is_constructible_v&lt;T, Args..., const Alloc&amp;&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>
</blockquote>
[&hellip;]
<pre>
template &lt;class T, class Alloc, class Tuple1, class Tuple2&gt;
  constexpr auto uses_allocator_construction_args(const Alloc&amp; alloc, piecewise_construct_t,
                                        Tuple1&amp;&amp; x, Tuple2&amp;&amp; y) 
                                        noexcept -&gt; <i>see below</i>;
</pre>
<blockquote>
<p>
-6- <i>Constraints:</i> <code>T</code> is a specialization of <code>pair</code>.
<p/>
-7- <i>Effects:</i> For <code>T</code> specified as <ins>(possibly <code>const</code>)</ins> <code>pair&lt;T1, T2&gt;</code>, equivalent to:
<p/>
[&hellip;]
</p>
</blockquote>
</blockquote>
</li>
</ol>




</body>
</html>
