[gcc r17-2305] libstdc++: Validate bound consistently in repeat_view constructors.
Tomasz Kaminski
tkaminsk@gcc.gnu.org
Fri Jul 10 10:46:34 GMT 2026
https://gcc.gnu.org/g:c8c1f777617df6f1816900b779f32c80e016d7bd
commit r17-2305-gc8c1f777617df6f1816900b779f32c80e016d7bd
Author: Tomasz Kamiński <tkaminsk@redhat.com>
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 <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
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 39a50b03e457..3e0df8d083c0 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -7918,14 +7918,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...>
@@ -7936,7 +7939,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
More information about the Libstdc++-cvs
mailing list