[PATCH] libstdc++: Validate bound consistently in repeat_view constructors.
Jonathan Wakely
jwakely@redhat.com
Fri Jul 10 09:20:03 GMT 2026
On Fri, 10 Jul 2026 at 08:04, Tomasz Kamiński <tkaminsk@redhat.com> wrote:
>
> 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.
> ---
> Testing on x86_64-linux. *repeat* test passed.
> OK for trunk when all test passes?
>
> libstdc++-v3/include/std/ranges | 14 +++++++++++---
> 1 file changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
> index 39a50b03e45..ea69a6c8dee 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,12 @@ 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)))
> - { }
> + {
> + // _GLIBCXX_RESOLVE_LIB_DEFECTS
> + // 3772. repeat_view's piecewise constructor is missing Postconditions
We don't need the comment because this is a C++23 feature and the LWG
issue was resolved before publication of the C++23 standard. So this
is just what the C++23 standard says, not a defect against C++23 that
was resolved later.
OK for trunk and gcc-16 without the comment, thanks.
> + if constexpr (__detail::__is_signed_integer_like<_Bound>)
> + __glibcxx_assert(_M_bound >= 0);
> + }
>
> constexpr _Iterator
> begin() const
> --
> 2.54.0
>
More information about the Libstdc++
mailing list