[gcc r16-9360] libstdc++: Validate bound consistently in repeat_view constructors.

Tomasz Kaminski via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <20260721150213.4C8384BA23C7__31264.4287057751$1784646200$gmane$org@sourceware.org>
https://gcc.gnu.org/g:91012a5cc7bd2fbc7376d675ff943c1122185dbc

commit r16-9360-g91012a5cc7bd2fbc7376d675ff943c1122185dbc
Author: Tomasz Kamiński <[email protected]>
Date:   Fri Jul 10 08:43:02 2026 +0200

    libstdc++: Validate bound consistently in repeat_view constructors.
    
    Add checks for bound being non-negative to _Tp&& __value and
    piecewise_construct_t constructor. The later resolves LWG3772,
    "repeat_view's piecewise constructor is missing Postconditions".
    
    We use __detail::__is_signed_integer_like<_Bound> as the condition
    for performing the check, to avoid checking it for unsigned integers
    for which it is trivially met. As _Bound is constrained to either
    unreachable_sentinel_t or integer-like, this gives equivalent behavior
    to standard specified !same_as<_Bound, unreachable_sentinel_t>.
    
    libstdc++-v3/ChangeLog:
    
            * include/std/ranges (repeat_view::repeat_view): Assert that
            __bound >= 0 consistently. Replace !same_as<unreachable_sentinel>
            with __is_signed_integer_like check.
    
    Reviewed-by: Jonathan Wakely <[email protected]>
    Signed-off-by: Tomasz Kamiński <[email protected]>
    (cherry picked from commit c8c1f777617df6f1816900b779f32c80e016d7bd)

Diff:
---
 libstdc++-v3/include/std/ranges | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index 4f2082487d1d..686ed93a916d 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -7902,14 +7902,17 @@ namespace views::__adaptor
     requires copy_constructible<_Tp>
     : _M_value(__value), _M_bound(__bound)
     {
-      if constexpr (!same_as<_Bound, unreachable_sentinel_t>)
+      if constexpr (__detail::__is_signed_integer_like<_Bound>)
 	__glibcxx_assert(__bound >= 0);
     }
 
     constexpr explicit
     repeat_view(_Tp&& __value, _Bound __bound = _Bound())
     : _M_value(std::move(__value)), _M_bound(__bound)
-    { }
+    {
+      if constexpr (__detail::__is_signed_integer_like<_Bound>)
+	__glibcxx_assert(__bound >= 0);
+    }
 
     template<typename... _Args, typename... _BoundArgs>
       requires constructible_from<_Tp, _Args...>
@@ -7920,7 +7923,10 @@ namespace views::__adaptor
 		tuple<_BoundArgs...> __bound_args = tuple<>{})
     : _M_value(std::make_from_tuple<_Tp>(std::move(__args))),
       _M_bound(std::make_from_tuple<_Bound>(std::move(__bound_args)))
-    { }
+    {
+      if constexpr (__detail::__is_signed_integer_like<_Bound>)
+	__glibcxx_assert(_M_bound >= 0);
+    }
 
     constexpr _Iterator
     begin() const
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.