Skip to content

Commit a34bf12

Browse files
committed
New issue from Hewill: "basic_string_view(It begin, End end) is underconstrained"
1 parent 1ae9907 commit a34bf12

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

xml/issue4410.xml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?xml version='1.0' encoding='utf-8' standalone='no'?>
2+
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+
<issue num="4410" status="New">
5+
<title>`basic_string_view(It begin, End end)` is underconstrained</title>
6+
<section>
7+
<sref ref="[string.view.cons]"/>
8+
</section>
9+
<submitter>Hewill Kang</submitter>
10+
<date>12 Oct 2025</date>
11+
<priority>99</priority>
12+
13+
<discussion>
14+
<p>
15+
The following lead to a hard error in the <code>string_view</code> constructor
16+
(<a href="https://godbolt.org/z/dz3M3fevc">demo</a>):
17+
</p>
18+
<blockquote><pre>
19+
volatile char* p;
20+
std::string_view sv(p, p); // <span style="color:red;font-weight:bolder">error: invalid conversion from 'volatile char*' to 'const char*'</span>
21+
</pre></blockquote>
22+
<p>
23+
Because the constructor currently only requires that the value type of the contiguous iterator be
24+
`char`, which does not reject `volatile char*`, which fires when further initializing `const char*`.
25+
</p>
26+
</discussion>
27+
28+
<resolution>
29+
<p>
30+
This wording is relative to <paper num="N5014"/>.
31+
</p>
32+
33+
<ol>
34+
35+
<li><p>Modify <sref ref="[string.view.cons]"/> as indicated:</p>
36+
37+
<blockquote>
38+
<pre>
39+
template&lt;class It, class End&gt;
40+
constexpr basic_string_view(It begin, End end);
41+
</pre>
42+
<blockquote>
43+
<p>
44+
-7- <i>Constraints</i>:
45+
</p>
46+
<ol style="list-style-type: none">
47+
<li><p>
48+
(7.1) &mdash; `It` satisfies `contiguous_iterator`.
49+
</p></li>
50+
<li><p>
51+
(7.2) &mdash; `End` satisfies <code>sized_sentinel_for&lt;It&gt;</code>.
52+
</p></li>
53+
<li><p>
54+
(7.3) &mdash; <code>is_same_v&lt;iter_value_t&lt;It&gt;, charT&gt;</code> is `true`.
55+
</p></li>
56+
<li><p>
57+
<ins>(7.?) &mdash; <code>is_convertible_v&lt;add_pointer_t&lt;iter_reference_t&lt;It&gt;&gt;, const_pointer&gt;</code>
58+
is `true`.</ins>
59+
</p></li>
60+
<li><p>
61+
(7.4) &mdash; <code>is_convertible_v&lt;End, size_type&gt;</code> is `false`.
62+
</p></li>
63+
</ol>
64+
[&hellip;]
65+
</blockquote>
66+
<pre>
67+
template&lt;class R&gt;
68+
constexpr explicit basic_string_view(R&amp;&amp; r);
69+
</pre>
70+
<blockquote>
71+
<p>
72+
-11- Let `d` be an lvalue of type <code>remove_cvref_t&lt;R&gt;</code>.
73+
<p/>
74+
-12- <i>Constraints</i>:
75+
</p>
76+
<ol style="list-style-type: none">
77+
<li><p>
78+
(12.1) &mdash; <code>remove_cvref_t&lt;R&gt;</code> is not the same type as `basic_string_view`,
79+
</p></li>
80+
<li><p>
81+
(12.2) &mdash; `R` models `ranges::contiguous_range` and `ranges::sized_range`,
82+
</p></li>
83+
<li><p>
84+
(12.3) &mdash; <code>is_same_v&lt;ranges::range_value_t&lt;R&gt;, charT&gt;</code> is `true`,
85+
</p></li>
86+
<li><p>
87+
<ins>(12.?) &mdash; <code>is_convertible_v&lt;add_pointer_t&lt;ranges::range_reference_t&lt;R&gt;&gt;,
88+
const_pointer&gt;</code> is `true`,</ins>
89+
</p></li>
90+
<li><p>
91+
(12.4) &mdash; <code>is_convertible_v&lt;R, const charT*&gt;</code> is `false`, and
92+
</p></li>
93+
<li><p>
94+
(12.5) &mdash; <code>d.operator ::std::basic_string_view&lt;charT, traits&gt;()</code> is not a
95+
valid expression.
96+
</p></li>
97+
</ol>
98+
<p>
99+
</p>
100+
</blockquote>
101+
</blockquote>
102+
</li>
103+
104+
</ol>
105+
106+
</resolution>
107+
108+
</issue>

0 commit comments

Comments
 (0)