Title
Inconsistent preconditions in repeat_view::iterator
Status
new
Section
[range.repeat.iterator]
Submitter
Tomasz Kamiński

Created on 2026-09-21.00:00:00 last changed 5 days ago

Messages

Date: 2026-09-21.13:02:18

Proposed resolution:

This wording is relative to N5054.

The proposed resolution completely removes the precondition on private constructor iterator(const T* value, index-type b = index-type()), as it is private and can only be invoked by the library internally.

  1. Modify [range.repeat.iterator] as indicated:

    constexpr explicit iterator(const T* value, index-type b = index-type());
    

    -1- Preconditions: If `Bound` is not `unreachable_sentinel_t`, `b` ≥ 0.

    -2- Effects: […]

    […]
    constexpr explicit iterator& operator--();
    

    -6- Preconditions: If `Bound` is not `unreachable_sentinel_t`, current_ ≥ 0.

    -7- Effects: […]

    constexpr explicit iterator& operator+=(difference_type n);
    

    -8- Preconditions: If `Bound` is not `unreachable_sentinel_t`, current_ + `n` ≥ 0.

    -9- Effects: […]

    constexpr explicit iterator& operator-=(difference_type n);
    

    -10- Preconditions: If `Bound` is not `unreachable_sentinel_t`, current_ - `n` ≥ 0.

    -11- Effects: […]

Date: 2026-09-21.00:00:00

As currently specified, the preconditions requiring current_ to be non-negative ([range.repeat.iterator] p2, p6, p8, p10) are applied only if "If Bound is not unreachable_sentinel_t". In consequence, decrementing iterator before begin is UB only if `views::repeat` specifies bound:

auto rv1 = views::repeat(1, 10);
auto it1 = std::prev(rv1.begin()); // UB
auto rv2 = views::repeat(1);
auto it2 = std::prev(rv2.begin()); // OK
In contrast to the precondition on `bound` in `repeat_view` constructor, the current_ is of `ptrdiff_t` type in such case, and the check can always be performed.

On the LWG reflector Michał Dominiak (the author of the paper) confirmed, that this is unintentional copy-paste error in the wording, and the precondition should always be applied.

History
Date User Action Args
2026-09-21 13:02:18adminsetmessages: + msg16621
2026-09-21 00:00:00admincreate