Skip to content

Commit 816d241

Browse files
committed
New issue from Hewill: "subrange should prevent slicing for contiguous iterators"
1 parent c9fe2f4 commit 816d241

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

xml/issue4565.xml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version='1.0' encoding='utf-8' standalone='no'?>
2+
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+
<issue num="4565" status="New">
5+
<title><code>subrange</code> should prevent slicing for contiguous iterators</title>
6+
<section>
7+
<sref ref="[range.subrange.general]"/>
8+
</section>
9+
<submitter>Hewill Kang</submitter>
10+
<date>03 Apr 2026</date>
11+
<priority>99</priority>
12+
13+
<discussion>
14+
<p>
15+
Currently, the <code>subrange</code> uses the following exposition-only concept:
16+
</p>
17+
<blockquote><pre>
18+
template&lt;class From, class To&gt;
19+
concept <i>uses-nonqualification-pointer-conversion</i> = // <i>exposition only</i>
20+
is_pointer_v&lt;From&gt; &amp;&amp; is_pointer_v&lt;To&gt; &amp;&amp;
21+
!convertible_to&lt;remove_pointer_t&lt;From&gt;(*)[], remove_pointer_t&lt;To&gt;(*)[]&gt;;
22+
</pre></blockquote>
23+
<p>
24+
to disallow derived to base conversions. However, this only applies to pointers.
25+
</p>
26+
<p>
27+
Given that <code>subrange</code> is intended to universally take any iterator-pair to
28+
form a view, we may need to generally prevent this in the case of contiguous iterators
29+
(<a href="https://godbolt.org/z/oPvvExxaT">demo</a>):
30+
</p>
31+
<blockquote><pre>
32+
struct Base {};
33+
struct Derived : Base {};
34+
ranges::subrange&lt;Derived*&gt; sd;
35+
ranges::subrange&lt;Base*&gt; sb = sd; // error
36+
ranges::subrange&lt;const Base*&gt; sb = views::as_const(sd); // <span style="color:#C80000;font-weight:bold">ok</span>
37+
</pre></blockquote>
38+
</discussion>
39+
40+
<resolution>
41+
<p>
42+
This wording is relative to <paper num="N5032"/>.
43+
</p>
44+
45+
<ol>
46+
<li>
47+
<p>Modify <sref ref="[range.subrange.general]"/> as indicated:</p>
48+
49+
<blockquote>
50+
<pre>
51+
namespace std::ranges {
52+
template&lt;class From, class To&gt;
53+
concept <i>uses-nonqualification-pointer-conversion</i> = // <i>exposition only</i>
54+
<del>is_pointer_v</del><ins>contiguous_iterator</ins>&lt;From&gt; &amp;&amp; <del>is_pointer_v</del><ins>contiguous_iterator</ins>&lt;To&gt; &amp;&amp;
55+
!convertible_to&lt;<del>remove_pointer_t</del><ins>remove_reference_t&lt;iter_reference_t</ins>&lt;From&gt;<ins>&gt;</ins>(*)[],
56+
<del>remove_pointer_t</del><ins>remove_reference_t&lt;iter_reference_t</ins>&lt;To&gt;<ins>&gt;</ins>(*)[]&gt;;
57+
[&hellip;]
58+
}
59+
</pre>
60+
</blockquote>
61+
</li>
62+
63+
</ol>
64+
</resolution>
65+
66+
</issue>

0 commit comments

Comments
 (0)