On Mon, 21 Sep 2026 at 13:54 +0200, Tomasz KamiĆski wrote:
This implements LWG4624, "Inconsistent preconditions in repeat_view::iterator".
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.
The assert in private _Iterator(const _Tp*, __index_type) constructor are
removed entirelly, as the constructor can only be called internally.
libstdc++-v3/ChangeLog:
* include/std/ranges (repeat_view::_Iterator::_Iterator):
Remove assert, as constructor is used only iternally.
(repeat_view::_Iterator::operator--)
(repeat_view::_Iterator::operator+=)
(repeat_view::_Iterator::operator-=): Unconditionally assert
on _M_current having non-negative value.
---
v2:
* links to LWG4624 that I have created to address the wording
* (as part of above) removes the assert in the private constructor
Tested on x86_64-linux. *random* also tested in all standard modes,
assertion debug. OK for trunk? Do we want to wait for issue votes?
OK for trunk
libstdc++-v3/include/std/ranges | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index 1c0991cae13..fe7c87b8f6e 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);
- }
+ { }
friend repeat_view;
@@ -8112,8 +8109,9 @@ namespace views::__adaptor
constexpr _Iterator&
operator--()
{
- if constexpr (!same_as<_Bound, unreachable_sentinel_t>)
- __glibcxx_assert(_M_current > 0);
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 4624. Inconsistent preconditions in repeat_view::iterator
+ __glibcxx_assert(_M_current > 0);
--_M_current;
return *this;
}
@@ -8129,8 +8127,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 +8135,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