This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.
basic_string_view(It begin, End end)
is underconstrainedSection: 27.3.3.2 [string.view.cons] Status: New Submitter: Hewill Kang Opened: 2025-10-12 Last modified: 2025-10-12
Priority: Not Prioritized
View other active issues in [string.view.cons].
View all other issues in [string.view.cons].
View all issues with New status.
Discussion:
The following lead to a hard error in the string_view
constructor
(demo):
volatile char* p;
std::string_view sv(p, p); // error: invalid conversion from 'volatile char*' to 'const char*'
Because the constructor currently only requires that the value type of the contiguous iterator be
char
, which does not reject volatile char*
, which fires when further initializing const char*
.
Proposed resolution:
This wording is relative to N5014.
Modify 27.3.3.2 [string.view.cons] as indicated:
template<class It, class End> constexpr basic_string_view(It begin, End end);-7- Constraints:
[…]
(7.1) —
It
satisfiescontiguous_iterator
.(7.2) —
End
satisfiessized_sentinel_for<It>
.(7.3) —
is_same_v<iter_value_t<It>, charT>
istrue
.(7.?) —
is_convertible_v<add_pointer_t<iter_reference_t<It>>, const_pointer>
istrue
.(7.4) —
is_convertible_v<End, size_type>
isfalse
.template<class R> constexpr explicit basic_string_view(R&& r);-11- Let
-12- Constraints:d
be an lvalue of typeremove_cvref_t<R>
.
(12.1) —
remove_cvref_t<R>
is not the same type asbasic_string_view
,(12.2) —
R
modelsranges::contiguous_range
andranges::sized_range
,(12.3) —
is_same_v<ranges::range_value_t<R>, charT>
istrue
,(12.?) —
is_convertible_v<add_pointer_t<ranges::range_reference_t<R>>, const_pointer>
istrue
,(12.4) —
is_convertible_v<R, const charT*>
isfalse
, and(12.5) —
d.operator ::std::basic_string_view<charT, traits>()
is not a valid expression.