On Fri, Sep 18, 2026 at 4:50 PM Tomasz Kamiński <[email protected]> wrote:
> The checks against _M_current being negive were disabled for cases where
> _Bound denotes unreachable_sentinel_t. However, _M_current has ptrdiff_t
> type in that case, and this check are as meaningfull are for integer bound.
>
> libstdc++-v3/ChangeLog:
>
> * include/std/ranges (repeat_view::_Iterator::_Iterator)
> (repeat_view::_Iterator::operator--)
> (repeat_view::_Iterator::operator+=)
> (repeat_view::_Iterator::operator-=): Unconditionally assert
> on _M_current having non-negative value.
> ---
> Noticed that when working on extracting _Repeat_iterator (that I
> templated with _IndexType). Worth to be separate.
>
I wonder if it makes sense to modify the standard, to say that
views::repeat(x, n) is equivalent to repeate_view<T, ptrdiff_t> if
n is integral an numeric_limits<decltype(x)>::max <= ptrdiff_max_t.
This reduces the number of template instantiations, but is technically
breaking. Maybe it is too late.
>
> Testing on x86_64-linux. *repeat* view passed with all standard
> modes, debug and assertions. OK for trunk?
>
> libstdc++-v3/include/std/ranges | 14 ++++----------
> 1 file changed, 4 insertions(+), 10 deletions(-)
>
> diff --git a/libstdc++-v3/include/std/ranges
> b/libstdc++-v3/include/std/ranges
> index 1c0991cae13..a0ce157d4f2 100644
> --- a/libstdc++-v3/include/std/ranges
> +++ b/libstdc++-v3/include/std/ranges
> @@ -8075,10 +8075,7 @@ namespace views::__adaptor
> constexpr explicit
> _Iterator(const _Tp* __value, __index_type __bound = __index_type())
> : _M_value(__value), _M_current(__bound)
> - {
> - if constexpr (!same_as<_Bound, unreachable_sentinel_t>)
> - __glibcxx_assert(__bound >= 0);
> - }
> + { __glibcxx_assert(__bound >= 0); }
>
> friend repeat_view;
>
> @@ -8112,8 +8109,7 @@ namespace views::__adaptor
> constexpr _Iterator&
> operator--()
> {
> - if constexpr (!same_as<_Bound, unreachable_sentinel_t>)
> - __glibcxx_assert(_M_current > 0);
> + __glibcxx_assert(_M_current > 0);
> --_M_current;
> return *this;
> }
> @@ -8129,8 +8125,7 @@ namespace views::__adaptor
> constexpr _Iterator&
> operator+=(difference_type __n)
> {
> - if constexpr (!same_as<_Bound, unreachable_sentinel_t>)
> - __glibcxx_assert(_M_current + __n >= 0);
> + __glibcxx_assert(_M_current + __n >= 0);
> _M_current += __n;
> return *this;
> }
> @@ -8138,8 +8133,7 @@ namespace views::__adaptor
> constexpr _Iterator&
> operator-=(difference_type __n)
> {
> - if constexpr (!same_as<_Bound, unreachable_sentinel_t>)
> - __glibcxx_assert(_M_current - __n >= 0);
> + __glibcxx_assert(_M_current - __n >= 0);
> _M_current -= __n;
> return *this;
> }
> --
> 2.55.0
>
>