|
| 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<class It, class End> |
| 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) — `It` satisfies `contiguous_iterator`. |
| 49 | +</p></li> |
| 50 | +<li><p> |
| 51 | +(7.2) — `End` satisfies <code>sized_sentinel_for<It></code>. |
| 52 | +</p></li> |
| 53 | +<li><p> |
| 54 | +(7.3) — <code>is_same_v<iter_value_t<It>, charT></code> is `true`. |
| 55 | +</p></li> |
| 56 | +<ins>(7.?) — <code>is_convertible_v<add_pointer_t<iter_reference_t<It>>, const_pointer></code> |
| 57 | +is `true`.</ins> |
| 58 | +<li><p> |
| 59 | +(7.4) — <code>is_convertible_v<End, size_type></code> is `false`. |
| 60 | +</p></li> |
| 61 | +</ol> |
| 62 | +[…] |
| 63 | +</blockquote> |
| 64 | +<pre> |
| 65 | +template<class R> |
| 66 | + constexpr explicit basic_string_view(R&& r); |
| 67 | +</pre> |
| 68 | +<blockquote> |
| 69 | +<p> |
| 70 | +-11- Let `d` be an lvalue of type <code>remove_cvref_t<R></code>. |
| 71 | +<p/> |
| 72 | +-12- <i>Constraints</i>: |
| 73 | +</p> |
| 74 | +<ol style="list-style-type: none"> |
| 75 | +<li><p> |
| 76 | +(12.1) — <code>remove_cvref_t<R></code> is not the same type as `basic_string_view`, |
| 77 | +</p></li> |
| 78 | +<li><p> |
| 79 | +(12.2) — `R` models `ranges::contiguous_range` and `ranges::sized_range`, |
| 80 | +</p></li> |
| 81 | +<li><p> |
| 82 | +(12.3) — <code>is_same_v<ranges::range_value_t<R>, charT></code> is `true`, |
| 83 | +</p></li> |
| 84 | +<li><p> |
| 85 | +<ins>(12.?) — <code>is_convertible_v<add_pointer_t<ranges::range_reference_t<R>>, |
| 86 | +const_pointer></code> is `true`,</ins> |
| 87 | +</p></li> |
| 88 | +<li><p> |
| 89 | +(12.4) — <code>is_convertible_v<R, const charT*></code> is `false`, and |
| 90 | +</p></li> |
| 91 | +<li><p> |
| 92 | +(12.5) — <code>d.operator ::std::basic_string_view<charT, traits>()</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