<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3007: allocate_shared should rebind allocator to cv-unqualified value_type for construction</title>
<meta property="og:title" content="Issue 3007: allocate_shared should rebind allocator to cv-unqualified value_type for construction">
<meta property="og:description" content="C++ library issue. Status: C++20">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3007.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="3007"><a href="lwg-defects.html#3007">3007</a>. <code>allocate_shared</code> should rebind allocator to <i>cv</i>-unqualified <code>value_type</code> for construction</h3>
<p><b>Section:</b> 20.3.2.2.7 <a href="https://wg21.link/util.smartptr.shared.create">[util.smartptr.shared.create]</a> <b>Status:</b> <a href="lwg-active.html#C++20">C++20</a>
 <b>Submitter:</b> Glen Joseph Fernandes <b>Opened:</b> 2017-08-06 <b>Last modified:</b> 2021-02-25</p>
<p><b>Priority: </b>0
</p>
<p><b>View all other</b> <a href="lwg-index.html#util.smartptr.shared.create">issues</a> in [util.smartptr.shared.create].</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>
The remarks for the <code>allocate_shared</code> family of functions
specify that when constructing a (sub)object of type <code>U</code>, it uses a
rebound copy of the allocator <code>a</code> passed to
<code>allocate_shared</code> such that its <code>value_type</code> is
<code>U</code>. However <code>U</code> can be a <code>const</code> or
<code>volatile</code> qualified type, and [allocator.requirements] specify
that the <code>value_type</code> must be <i>cv</i>-unqualified.
</p>

<p><i>[
2017-11-01 Moved to Tentatively Ready after 6 positive votes for P0 on c++std-lib.
]</i></p>

<p><i>[2018-3-17 Adopted in Jacksonville]</i></p>



<p id="res-3007"><b>Proposed resolution:</b></p>
<p>This resolution is relative to <a href="https://wg21.link/n4687">N4687</a>.</p>

<ol>
<li><p>Edit 20.3.2.2.7 <a href="https://wg21.link/util.smartptr.shared.create">[util.smartptr.shared.create]</a> as indicated:</p>

<blockquote>
<pre>
template&lt;class T, ...&gt;
shared_ptr&lt;T&gt; make_shared(<i>args</i>);
template&lt;class T, class A, ...&gt;
shared_ptr&lt;T&gt; allocate_shared(const A&amp; a, <i>args</i>);
</pre>
<blockquote>
<p>
[&hellip;]
<p/>
-7- <i>Remarks:</i>
</p>
<ol style="list-style-type: none">
<li><p>[&hellip;]</p></li>
<li><p>(7.5) &mdash; When a (sub)object of a non-array type <code>U</code> is specified to have an initial value of <code>v</code>, 
or <code>U(l...)</code>, where <code>l...</code> is a list of constructor arguments, <code>allocate_shared</code> shall initialize this 
(sub)object via the expression</p>
<ol style="list-style-type: none">
<li><p>(7.5.1) &mdash; <code>allocator_traits&lt;A2&gt;::construct(a2, pv, v)</code> or</p></li>
<li><p>(7.5.2) &mdash; <code>allocator_traits&lt;A2&gt;::construct(a2, pv, l...)</code></p></li>
</ol>
<p>
respectively, where <code>pv</code> points to storage suitable to hold an object of type <code>U</code> and <code>a2</code> of 
type <code>A2</code> is a rebound copy of the allocator a passed to <code>allocate_shared</code> such that its 
<code>value_type</code> is <code><ins>remove_cv_t&lt;</ins>U<ins>&gt;</ins></code>.
</p>
</li>
<li><p>(7.6) &mdash; When a (sub)object of non-array type <code>U</code> is specified to have a default initial value, 
<code>make_shared</code> shall initialize this (sub)object via the expression <code>::new(pv) U()</code>, where <code>pv</code> 
has type <code>void*</code> and points to storage suitable to hold an object of type <code>U</code>.</p></li>
<li><p>(7.7) &mdash; When a (sub)object of non-array type <code>U</code> is specified to have a default initial value, 
<code>allocate_shared</code> shall initialize this (sub)object via the expression <code>allocator_traits&lt;A2&gt;::construct(a2, pv)</code>,
where <code>pv</code> points to storage suitable to hold an object of type <code>U</code> and <code>a2</code> of type <code>A2</code> 
is a rebound copy of the allocator a passed to <code>allocate_shared</code> such that its <code>value_type</code> is 
<code><ins>remove_cv_t&lt;</ins>U<ins>&gt;</ins></code>.</p></li>
<li><p>[&hellip;]</p></li>
</ol>
</blockquote>
</blockquote>
</li>

</ol>




</body>
</html>
