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.

4410. basic_string_view(It begin, End end) is underconstrained

Section: 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.

  1. 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:

    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.