<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2975: Missing case for pair construction in scoped and polymorphic allocators</title>
<meta property="og:title" content="Issue 2975: Missing case for pair construction in scoped and polymorphic allocators">
<meta property="og:description" content="C++ library issue. Status: C++20">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2975.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="2975"><a href="lwg-defects.html#2975">2975</a>. Missing case for <code>pair</code> construction in scoped and polymorphic allocators</h3>
<p><b>Section:</b> 20.5.3.3 <a href="https://wg21.link/mem.poly.allocator.mem">[mem.poly.allocator.mem]</a>, 20.6.4 <a href="https://wg21.link/allocator.adaptor.members">[allocator.adaptor.members]</a> <b>Status:</b> <a href="lwg-active.html#C++20">C++20</a>
 <b>Submitter:</b> Casey Carter <b>Opened:</b> 2017-06-13 <b>Last modified:</b> 2021-02-25</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#C++20">C++20</a> status.</p>
<p><b>Discussion:</b></p>
<p>
<code>scoped_allocator_adaptor</code> ([allocator.adaptor.syn]) and <code>polymorphic_allocator</code> ([mem.poly.allocator.class]) 
have identical families of members named <code>construct</code>:
</p>
<blockquote>
<pre>
template &lt;class T, class... Args&gt;
  void construct(T* p, Args&amp;&amp;... args);

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);
template &lt;class T1, class T2&gt;
  void construct(pair&lt;T1,T2&gt;* p);
template &lt;class T1, class T2, class U, class V&gt;
  void construct(pair&lt;T1,T2&gt;* p, U&amp;&amp; x, V&amp;&amp; y);
template &lt;class T1, class T2, class U, class V&gt;
  void construct(pair&lt;T1,T2&gt;* p, const pair&lt;U, V&gt;&amp; pr);
template &lt;class T1, class T2, class U, class V&gt;
  void construct(pair&lt;T1,T2&gt;* p, pair&lt;U, V&gt;&amp;&amp; pr);
</pre>
</blockquote>
<p>
Both allocators perform <code>uses_allocator</code> construction, and therefore need special handling for <code>pair</code> 
constructions since <code>pair</code> doesn't specialize <code>uses_allocator</code> (<code>tuple</code> gets all of that magic 
and <code>pair</code> is left out in the cold). Presumably, the intent is that the <code>construct</code> overloads whose first 
argument is a pointer to <code>pair</code> capture all <code>pair</code> constructions. This is not the case: invoking 
<code>construct</code> with a <code>pair</code> pointer and a non-constant lvalue <code>pair</code> resolves to the <em>first</em> 
overload when it is viable: it's a better match than the <code>pair</code>-pointer-and-<code>const</code>-lvalue-<code>pair</code> 
overload. The first overload notably does not properly perform piecewise <code>uses_allocator</code> construction for 
<code>pair</code>s as intended.
</p>

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

<p>Priority 2; Marshall to work with Casey to reduce the negations in the wording.</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<ol>
<li>
<p>Modify 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>resource()</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>resource()</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/>
<ins>-?- <i>Remarks:</i> This function shall not participate in overload resolution unless <code>T</code> is not a specialization 
of <code>pair</code>.</ins>
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>Modify 20.6.4 <a href="https://wg21.link/allocator.adaptor.members">[allocator.adaptor.members]</a> as indicated:</p>

<blockquote>
<pre>
template &lt;class T, class... Args&gt;
  void construct(T* p, Args&amp;&amp;... args);
</pre>
<blockquote>
<p>
-9- <i>Effects:</i> [&hellip;]
<p/>
<ins>-?- <i>Remarks:</i> This function shall not participate in overload resolution unless <code>T</code> is not a specialization 
of <code>pair</code>.</ins>
</p>
</blockquote>
</blockquote>
</li>
</ol>

</blockquote>

<p><i>[2017-11-02 Marshall and Casey provide updated wording]</i></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-2975"><b>Proposed resolution:</b></p>
<p>This wording is relative to <a href="https://wg21.link/n4659">N4659</a>.</p>

<ol>
<li>
<p>Modify 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>resource()</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>resource()</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/>
<ins>-?- <i>Remarks:</i> This function shall not participate in overload resolution if <code>T</code> is a specialization 
of <code>pair</code>.</ins>
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>Modify 20.6.4 <a href="https://wg21.link/allocator.adaptor.members">[allocator.adaptor.members]</a> as indicated:</p>

<blockquote>
<pre>
template &lt;class T, class... Args&gt;
  void construct(T* p, Args&amp;&amp;... args);
</pre>
<blockquote>
<p>
-9- <i>Effects:</i> [&hellip;]
<p/>
<ins>-?- <i>Remarks:</i> This function shall not participate in overload resolution if <code>T</code> is a specialization 
of <code>pair</code>.</ins>
</p>
</blockquote>
</blockquote>
</li>
</ol>






</body>
</html>
