Title
`basic_string_view(It begin, End end)` is underconstrained
Status
new
Section
[string.view.cons]
Submitter
Hewill Kang

Created on 2025-10-12.00:00:00 last changed 1 month ago

Messages

Date: 2025-10-17.12:42:49

Proposed resolution:

This wording is relative to N5014.

  1. Modify [string.view.cons] as indicated:

    template<class It, class End>
      constexpr basic_string_view(It begin, End end);
    

    -7- Constraints:

    1. (7.1) — `It` satisfies `contiguous_iterator`.

    2. (7.2) — `End` satisfies sized_sentinel_for<It>.

    3. (7.3) — is_same_v<iter_value_t<It>, charT> is `true`.

    4. (7.?) — is_convertible_v<add_pointer_t<iter_reference_t<It>>, const_pointer> is `true`.

    5. (7.4) — is_convertible_v<End, size_type> is `false`.

    […]
    template<class R>
      constexpr explicit basic_string_view(R&& r);
    

    -11- Let `d` be an lvalue of type remove_cvref_t<R>.

    -12- Constraints:

    1. (12.1) — remove_cvref_t<R> is not the same type as `basic_string_view`,

    2. (12.2) — `R` models `ranges::contiguous_range` and `ranges::sized_range`,

    3. (12.3) — is_same_v<ranges::range_value_t<R>, charT> is `true`,

    4. (12.?) — is_convertible_v<add_pointer_t<ranges::range_reference_t<R>>, const_pointer> is `true`,

    5. (12.4) — is_convertible_v<R, const charT*> is `false`, and

    6. (12.5) — d.operator ::std::basic_string_view<charT, traits>() is not a valid expression.

Date: 2025-10-15.00:00:00

[ 2025-10-17; Reflector poll. ]

Set priority to 4 after reflector poll.

"NAD, don't care about volatile." "Maybe make it Mandates: instead of Constraints:." "We already reject span<const char> s(p,p) so should also reject `string_view sv(p,p)`."

Date: 2025-10-12.00:00:00

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*`.

History
Date User Action Args
2025-10-17 12:42:49adminsetmessages: + msg15213
2025-10-12 17:10:02adminsetmessages: + msg15151
2025-10-12 00:00:00admincreate