GCC Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
libstdc++

libstdc++: Validate bound consistently in repeat_view constructors.

Ensures non-negative bound checks in `std::ranges::repeat_view` constructors.

The constructors for std::ranges::repeat_view now consistently validate that the bound (specifying the number of repetitions) is non-negative. This change addresses LWG3772 by adding assertions for both the value-based and piecewise_construct_t constructors, ensuring that unsigned bound types are handled correctly and preventing runtime errors or unexpected behavior with negative bounds.

In Details

This commit enforces the non-negative bound requirement for std::ranges::repeat_view in all relevant constructors, including the piecewise_construct_t constructor which was previously missing this check (LWG3772). It uses __detail::__is_signed_integer_like<_Bound> to selectively apply the check only when _Bound is a signed integer type, avoiding unnecessary checks for unsigned types or unreachable_sentinel_t.

For Context
libstdc++
The C++ standard library implementation used by GCC.
std::ranges::repeat_view
A C++20 utility that creates a view generating a specified value repeatedly for a given number of times (the bound).
bound
In the context of repeat_view, the bound specifies how many times a value should be repeated.
LWG3772
A specific issue (numbered 3772) raised and resolved by the C++ Library Working Group (LWG), concerning missing postconditions and incorrect behavior in a repeat_view constructor.
piecewise_construct_t
A tag type used in C++ to indicate that a constructor should construct its members piecewise, often used for tuple-like objects.
Filed Under: libstdc++rangeserror handlingcpp20