<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3068: Forbid assigning an rvalue basic_string to basic_string_view</title>
<meta property="og:title" content="Issue 3068: Forbid assigning an rvalue basic_string to basic_string_view">
<meta property="og:description" content="C++ library issue. Status: NAD">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3068.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#NAD">NAD</a> status.</em></p>
<h3 id="3068"><a href="lwg-closed.html#3068">3068</a>. Forbid assigning an rvalue <code>basic_string</code> to <code>basic_string_view</code></h3>
<p><b>Section:</b> 27.3.3 <a href="https://wg21.link/string.view.template">[string.view.template]</a> <b>Status:</b> <a href="lwg-active.html#NAD">NAD</a>
 <b>Submitter:</b> Antony Polukhin <b>Opened:</b> 2018-02-19 <b>Last modified:</b> 2022-08-24</p>
<p><b>Priority: </b>2
</p>
<p><b>View all other</b> <a href="lwg-index.html#string.view.template">issues</a> in [string.view.template].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#NAD">NAD</a> status.</p>
<p><b>Discussion:</b></p>
<p>
It is known that we cannot disable move construction of
<code>basic_string_view</code> from rvalues of <code>basic_string</code>, because it breaks a
valid use case:
</p>
<blockquote><pre>
string foo();
void bar(string_view );
bar(foo());
</pre></blockquote>
<p>
Though it is still possible to disable an absolutely wrong case of
assigning an rvalue <code>basic_string</code> to <code>basic_string_view</code>:
</p>
<blockquote><pre>
string_view sw = "Hello";
sw = foo();
</pre></blockquote>
<p>
Some tests that make sure that other use cases are not affected are available 
<a href="https://raw.githubusercontent.com/apolukhin/apolukhin.github.io/master/papers/misc/safer_string_view_tests.cpp">here</a>
</p>

<p><i>[2018-06-18 after reflector discussion]</i></p>

<p>Priority set to 2; status to LEWG</p>

<p><i>[2020-05-28; LEWG issue reviewing]</i></p>

<p>
LEWG issue processing voted to reject 3068 as NAD. Status change to Open.
</p>
<blockquote>
<pre>
SF F N A SA
15 5 1 0 0
</pre>
</blockquote>

<p><i>[2022-08-24 Status changed: Open &rarr; NAD.]</i></p>

<p>
LWG telecon: close based on LEWG direction.
"This makes string_view depend on basic_string."
"Request a paper with implementation if someone really wants this."
</p>



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

<ol>
<li><p>Change 27.3.3 <a href="https://wg21.link/string.view.template">[string.view.template]</a>, class template <code>basic_string_view</code> synopsis, 
as indicated:</p>
<blockquote>
<pre>
[&hellip;]
<i>// 27.3.3.2 <a href="https://wg21.link/string.view.cons">[string.view.cons]</a>, construction and assignment</i>
constexpr basic_string_view() noexcept;
constexpr basic_string_view(const basic_string_view&amp;) noexcept = default;
constexpr basic_string_view&amp; operator=(const basic_string_view&amp;) noexcept = default;
<ins>template &lt;class A&gt;
basic_string_view&amp; operator=(const basic_string&lt;charT, traits, A&gt;&amp;&amp;) = delete;</ins>
constexpr basic_string_view(const charT* str);
constexpr basic_string_view(const charT* str, size_type len);
[&hellip;]
</pre>
</blockquote>
</li>
</ol>





</body>
</html>
