<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2788: basic_string range mutators unintentionally require a default constructible allocator</title>
<meta property="og:title" content="Issue 2788: basic_string range mutators unintentionally require a default constructible allocator">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2788.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="2788"><a href="lwg-defects.html#2788">2788</a>. <code>basic_string</code> range mutators unintentionally require a default constructible allocator</h3>
<p><b>Section:</b> 27.4.3.7.2 <a href="https://wg21.link/string.append">[string.append]</a>, 27.4.3.7.3 <a href="https://wg21.link/string.assign">[string.assign]</a>, 27.4.3.7.4 <a href="https://wg21.link/string.insert">[string.insert]</a>, 27.4.3.7.6 <a href="https://wg21.link/string.replace">[string.replace]</a> <b>Status:</b> <a href="lwg-active.html#C++17">C++17</a>
 <b>Submitter:</b> Billy O'Neal III <b>Opened:</b> 2016-10-25 <b>Last modified:</b> 2017-07-30</p>
<p><b>Priority: </b>2
</p>
<p><b>View all other</b> <a href="lwg-index.html#string.append">issues</a> in [string.append].</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>
Email discussion occurred on the <a href="http://lists.isocpp.org/lib/2016/10/1154.php">lib reflector</a>.
<p/>
<code>basic_string</code>'s mutation functions show construction of temporary <code>basic_string</code> instances, 
without passing an allocator parameter. This says that <code>basic_string</code> needs to use a default-initialized 
allocator, which is clearly unintentional. The temporary needs to use the same allocator the current 
<code>basic_string</code> instance uses, if an implmentation needs to create a temporary at all.
<p/>
libc++ already does this; I believe libstdc++ does as well (due to the bug report we got from a user that brought 
this to our attention), but have not verified there. I implemented this in MSVC++'s STL and this change is scheduled 
to ship in VS "15" RTW.
</p>
<p><i>[2016-11-12, Issaquah]</i></p>

<p>Sat AM: Priority 2</p>
<p>Alisdair to investigate and (possibly) provide an alternate P/R</p>

<p><i>[2017-02-13 Alisdair responds:]</i></p>

<p>Looks good to me - no suggested alternative</p>

<p><i>[Kona 2017-02-28]</i></p>

<p>Accepted as Immediate.</p>


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

<ol>
<li><p>In 27.4.3.7.2 <a href="https://wg21.link/string.append">[string.append]</a>, add the allocator parameter to the range overload temporary:</p>

<blockquote>
<pre>
template&lt;class InputIterator&gt;
  basic_string&amp; append(InputIterator first, InputIterator last);
</pre>
<blockquote>
<p>
-19- <i>Requires:</i> <code>[first, last)</code> is a valid range.
<p/>
-20- <i>Effects:</i> Equivalent to <code>append(basic_string(first, last<ins>, get_allocator()</ins>))</code>.
<p/>
-21- <i>Returns:</i> <code>*this</code>.
</p>
</blockquote>
</blockquote>
</li>

<li><p>In 27.4.3.7.3 <a href="https://wg21.link/string.assign">[string.assign]</a>, add the allocator parameter to the range overload temporary:</p>

<blockquote>
<pre>
template&lt;class InputIterator&gt;
  basic_string&amp; assign(InputIterator first, InputIterator last);
</pre>
<blockquote>
<p>
-23- <i>Effects:</i> Equivalent to <code>assign(basic_string(first, last<ins>, get_allocator()</ins>))</code>.
<p/>
-24- <i>Returns:</i> <code>*this</code>.
</p>
</blockquote>
</blockquote>
</li>

<li><p>In 27.4.3.7.4 <a href="https://wg21.link/string.insert">[string.insert]</a>, add the allocator parameter to the range overload temporary:</p>

<blockquote>
<pre>
template&lt;class InputIterator&gt;
  iterator insert(const_iterator p, InputIterator first, InputIterator last);
</pre>
<blockquote>
<p>
-23- <i>Requires:</i> <code>p</code> is a valid iterator on <code>*this</code>. <code>[first, last)</code> is a valid range.
<p/>
-24- <i>Effects:</i> Equivalent to <code>insert(p - begin(), basic_string(first, last<ins>, get_allocator()</ins>))</code>.
<p/>
-25- <i>Returns:</i> An iterator which refers to the copy of the first inserted character, or <code>p</code> if <code>first == last</code>.
</p>
</blockquote>
</blockquote>
</li>

<li><p>In 27.4.3.7.6 <a href="https://wg21.link/string.replace">[string.replace]</a>, add the allocator parameter to the range overload temporary:</p>

<blockquote>
<pre>
template&lt;class InputIterator&gt;
  basic_string&amp; replace(const_iterator i1, const_iterator i2,
                        InputIterator j1, InputIterator j2);
</pre>
<blockquote>
<p>
-32- <i>Requires:</i> <code>[begin(), i1)</code>, <code>[i1, i2)</code> and <code>[j1, j2)</code> are valid ranges.
<p/>
-33- <i>Effects:</i> Calls <code>replace(i1 - begin(), i2 - i1, basic_string(j1, j2<ins>, get_allocator()</ins>))</code>.
<p/>
-34- <i>Returns:</i> <code>*this</code>.
</p>
</blockquote>
</blockquote>
</li>
</ol>





</body>
</html>
