GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
libstdc++

libstdc++: Unconditionally enable asserts in repeat_view::_Iterator

Improves iterator robustness in `repeat_view` by ensuring necessary assertions are always enabled, addressing LWG 4624.

This change ensures that assertions related to iterator validity in std::ranges::repeat_view are always enabled, regardless of the bound type. Previously, checks for a non-negative current iterator position were disabled when the bound was unreachable_sentinel_t, which was incorrect. Additionally, internal constructor assertions are removed as they are unreachable in normal use.

In Details

This commit addresses LWG 4624 by unconditionally enabling assertions in repeat_view::_Iterator for operator--, operator+=, and operator-=. The _M_current being non-negative check was previously disabled when _Bound was unreachable_sentinel_t, despite _M_current having a ptrdiff_t type in that scenario, making the check still relevant. Assertions in the private _Iterator(const _Tp*, __index_type) constructor are removed entirely, as this constructor is only invoked internally and its preconditions are guaranteed by the caller.

For Context
assertion
A statement in a program that must be true at a certain point for the program to continue correctly. Assertions are often used during development and debugging to catch unexpected states.
unreachable_sentinel_t
A type used in C++ ranges to represent a sentinel that is guaranteed to be distinct from any valid iterator, often used for unbounded ranges.
ptrdiff_t
A signed integer type capable of holding the difference between the pointers to any two elements in the same array.
LWG
Library Working Group, a committee responsible for evolving the C++ Standard Library.
Filed Under: libstdc++C++20rangesiteratorassertions