Skip to content

Commit 51e0d2b

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

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

xml/issue4410.xml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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+
<ins>(7.?) &mdash; <code>is_convertible_v&lt;add_pointer_t&lt;iter_reference_t&lt;It&gt;&gt;, const_pointer&gt;</code>
57+
is `true`.</ins>
58+
<li><p>
59+
(7.4) &mdash; <code>is_convertible_v&lt;End, size_type&gt;</code> is `false`.
60+
</p></li>
61+
</ol>
62+
[&hellip;]
63+
</blockquote>
64+
<pre>
65+
template&lt;class R&gt;
66+
constexpr explicit basic_string_view(R&amp;&amp; r);
67+
</pre>
68+
<blockquote>
69+
<p>
70+
-11- Let `d` be an lvalue of type <code>remove_cvref_t&lt;R&gt;</code>.
71+
<p/>
72+
-12- <i>Constraints</i>:
73+
</p>
74+
<ol style="list-style-type: none">
75+
<li><p>
76+
(12.1) &mdash; <code>remove_cvref_t&lt;R&gt;</code> is not the same type as `basic_string_view`,
77+
</p></li>
78+
<li><p>
79+
(12.2) &mdash; `R` models `ranges::contiguous_range` and `ranges::sized_range`,
80+
</p></li>
81+
<li><p>
82+
(12.3) &mdash; <code>is_same_v&lt;ranges::range_value_t&lt;R&gt;, charT&gt;</code> is `true`,
83+
</p></li>
84+
<li><p>
85+
<ins>(12.?) &mdash; <code>is_convertible_v&lt;add_pointer_t&lt;ranges::range_reference_t&lt;R&gt;&gt;,
86+
const_pointer&gt;</code> is `true`,</ins>
87+
</p></li>
88+
<li><p>
89+
(12.4) &mdash; <code>is_convertible_v&lt;R, const charT*&gt;</code> is `false`, and
90+
</p></li>
91+
<li><p>
92+
(12.5) &mdash; <code>d.operator ::std::basic_string_view&lt;charT, traits&gt;()</code> is not a
93+
valid expression.
94+
</p></li>
95+
</ol>
96+
<p>
97+
</p>
98+
</blockquote>
99+
</blockquote>
100+
</li>
101+
102+
</ol>
103+
104+
</resolution>
105+
106+
</issue>

0 commit comments

Comments
 (0)