<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3581: The range constructor makes basic_string_view not trivially move constructible</title>
<meta property="og:title" content="Issue 3581: The range constructor makes basic_string_view not trivially move constructible">
<meta property="og:description" content="C++ library issue. Status: C++23">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3581.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++23">C++23</a> status.</em></p>
<h3 id="3581"><a href="lwg-defects.html#3581">3581</a>. The range constructor makes <code>basic_string_view</code> not trivially move constructible</h3>
<p><b>Section:</b> 27.3.3.2 <a href="https://wg21.link/string.view.cons">[string.view.cons]</a> <b>Status:</b> <a href="lwg-active.html#C++23">C++23</a>
 <b>Submitter:</b> Jiang An, Casey Carter <b>Opened:</b> 2021-08-16 <b>Last modified:</b> 2023-11-22</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#string.view.cons">issues</a> in [string.view.cons].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++23">C++23</a> status.</p>
<p><b>Discussion:</b></p>
<p>
<b>Jiang An</b>:
</p>
<p>
 The issue is found in <a href="https://github.com/microsoft/STL/pull/2128">this Microsoft STL pull request</a>.
<p/>
I think an additional constraint should be added to 27.3.3.2 <a href="https://wg21.link/string.view.cons">[string.view.cons]</a>/11 (a similar constraint is 
already present for <code>reference_wrapper</code>):
</p>
<blockquote><p>
<ins>(11.?) &mdash; <code>is_same_v&lt;remove_cvref_t&lt;R&gt;, basic_string_view&gt;</code> is <code>false</code>.</ins>
</p></blockquote>
<p>
<b>Casey Carter</b>:
</p>
<p>
<a href="https://wg21.link/p1989R2">P1989R2</a> "Range constructor for <code>std::string_view</code> 2: Constrain Harder" 
added a converting constructor to <code>basic_string_view</code> that accepts (by forwarding reference) any sized 
contiguous range with a compatible element type. This constructor unfortunately intercepts attempts at move 
construction which previously would have resulted in a call to the copy constructor. (I suspect the authors of 
P1989 were under the mistaken impression that <code>basic_string_view</code> had a defaulted move constructor, which 
would sidestep this issue by being chosen by overload resolution via the "non-template vs. template" tiebreaker.)
<p/>
The resulting inefficiency could be corrected by adding a defaulted move constructor and move assignment operator 
to <code>basic_string_view</code>, but it would be awkward to add text to specify that these moves always leave the 
source intact. Presumably this is why the move operations were omitted in the first place. We therefore recommend 
constraining the conversion constructor template to reject arguments whose decayed type is <code>basic_string_view</code> 
(which we should probably do for all conversion constructor templates in the Standard Library).
<p/>
Implementation experience: MSVC STL is in the process of implementing this fix. Per Jonathan Wakely, libstdc++ has a 
similar constraint.
</p>

<p><i>[2021-09-20; Reflector poll]</i></p>

<p>
Set status to Tentatively Ready after nine votes in favour during reflector poll.
</p>

<p><i>[2021-10-14 Approved at October 2021 virtual plenary. Status changed: Voting &rarr; WP.]</i></p>



<p id="res-3581"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/n4892">N4892</a>.
</p>

<ol>
<li><p>Modify 27.3.3.2 <a href="https://wg21.link/string.view.cons">[string.view.cons]</a> as indicated:</p>

<blockquote>
<pre>
template&lt;class R&gt;
  constexpr basic_string_view(R&amp;&amp; r);
</pre>
<blockquote>
<p>
-10- Let <code>d</code> be an lvalue of type <code>remove_cvref_t&lt;R&gt;</code>.
<p/>
-11- <i>Constraints</i>:
</p>
<ol style="list-style-type: none">
<li><p><ins>(11.?) &mdash; <code>remove_cvref_t&lt;R&gt;</code> is not the same type as <code>basic_string_view</code>,</ins></p></li>
<li><p>(11.1) &mdash; <code>R</code> models <code>ranges::contiguous_range</code> and <code>ranges::sized_range</code>,</p></li>
<li><p>(11.2) &mdash; <code>is_same_v&lt;ranges::range_value_t&lt;R&gt;, charT&gt;</code> is <code>true</code>,</p></li>
<li><p>[&hellip;]</p></li>
</ol>
</blockquote>
</blockquote>
</li>

</ol>




</body>
</html>
