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.

4565. subrange should prevent slicing for contiguous iterators

Section: 25.5.4.1 [range.subrange.general] Status: New Submitter: Hewill Kang Opened: 2026-04-03 Last modified: 2026-04-04

Priority: Not Prioritized

View other active issues in [range.subrange.general].

View all other issues in [range.subrange.general].

View all issues with New status.

Discussion:

Currently, the subrange uses the following exposition-only concept:

template<class From, class To>
  concept uses-nonqualification-pointer-conversion =      // exposition only
    is_pointer_v<From> && is_pointer_v<To> &&
    !convertible_to<remove_pointer_t<From>(*)[], remove_pointer_t<To>(*)[]>;

to disallow derived to base conversions. However, this only applies to pointers.

Given that subrange is intended to universally take any iterator-pair to form a view, we may need to generally prevent this in the case of contiguous iterators (demo):

struct Base {};
struct Derived : Base {};
ranges::subrange<Derived*> sd;
ranges::subrange<Base*> sb = sd;                        // error
ranges::subrange<const Base*> sb = views::as_const(sd); // ok

Proposed resolution:

This wording is relative to N5032.

  1. Modify 25.5.4.1 [range.subrange.general] as indicated:

    namespace std::ranges {
      template<class From, class To>
        concept uses-nonqualification-pointer-conversion =      // exposition only
          is_pointer_vcontiguous_iterator<From> && is_pointer_vcontiguous_iterator<To> &&
          !convertible_to<remove_pointer_tremove_reference_t<iter_reference_t<From>>(*)[], 
                          remove_pointer_tremove_reference_t<iter_reference_t<To>>(*)[]>;
       […]
    }