https://gcc.gnu.org/g:168233d446e7b584debe4e8efa8719bbc3389ed1

commit r17-4777-g168233d446e7b584debe4e8efa8719bbc3389ed1
Author: Tomasz KamiƄski <[email protected]>
Date:   Tue Sep 29 18:51:11 2026 +0200

    libstdc++: Enable asserts in repeat_view::_Iterator uncoditionally.
    
    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.
    
    Reviewed-by: Jonathan Wakely <[email protected]>

Diff:
---
 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 1c0991cae138..fe7c87b8f6ee 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;
     }

Reply via email to