diff --git a/libcxx/include/__ranges/subrange.h b/libcxx/include/__ranges/subrange.h --- a/libcxx/include/__ranges/subrange.h +++ b/libcxx/include/__ranges/subrange.h @@ -118,7 +118,11 @@ constexpr subrange(__convertible_to_non_slicing<_Iter> auto __iter, _Sent __sent, make_unsigned_t> __n) requires (_Kind == subrange_kind::sized) - : _Base(_VSTD::move(__iter), __sent, __n) { } + : _Base(_VSTD::move(__iter), __sent, __n) + { + if constexpr (sized_sentinel_for<_Sent, decltype(__iter)>) + _LIBCPP_ASSERT(ranges::distance(this->__begin_, this->__end_) == __n, "std::ranges::subrange was passed an invalid size hint"); + } template<__different_from _Range> requires borrowed_range<_Range> &&