From 3268c47c08782efe7fb1dd9a110bebe018e7d59c Mon Sep 17 00:00:00 2001 From: Patrick Palka Date: Wed, 17 Sep 2025 14:14:37 -0400 Subject: [PATCH] libstdc++/ranges: Fix more wrong value type init from reference type [PR111861] As in r16-3912-g412a1f78b53709, this fixes some other spots where we wrongly use a deduced type and non-direct-initialization when trying to initialize a value type from an iterator's reference type. PR libstdc++/111861 libstdc++-v3/ChangeLog: * include/bits/ranges_algo.h (ranges::unique_copy): When initializing a value type object from *iter, use direct-initialization and don't use a deduced type. (ranges::push_heap): Use direct-initialization when initializing a value type object from ranges::iter_move. (ranges::max): As in ranges::unique_copy. * include/bits/ranges_util.h (ranges::min): Likewise. Reviewed-by: Jonathan Wakely --- libstdc++-v3/include/bits/ranges_algo.h | 8 ++++---- libstdc++-v3/include/bits/ranges_util.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libstdc++-v3/include/bits/ranges_algo.h b/libstdc++-v3/include/bits/ranges_algo.h index 4025bba9f20..5c9fe627aee 100644 --- a/libstdc++-v3/include/bits/ranges_algo.h +++ b/libstdc++-v3/include/bits/ranges_algo.h @@ -1529,7 +1529,7 @@ namespace ranges } else // indirectly_copyable_storable<_Iter, _Out> { - auto __value = *__first; + iter_value_t<_Iter> __value(*__first); *__result = __value; while (++__first != __last) { @@ -2075,9 +2075,9 @@ namespace ranges else { auto __comp_proj = __detail::__make_comp_proj(__comp, __proj); + iter_value_t<_Iter> __value(ranges::iter_move(ranges::prev(__last))); __detail::__push_heap(__first, (__last - __first) - 1, - 0, ranges::iter_move(ranges::prev(__last)), - __comp_proj); + 0, std::move(__value), __comp_proj); return __last; } } @@ -4219,7 +4219,7 @@ namespace ranges auto __first = ranges::begin(__r); auto __last = ranges::end(__r); __glibcxx_assert(__first != __last); - auto __result = *__first; + range_value_t<_Range> __result(*__first); while (++__first != __last) { auto&& __tmp = *__first; diff --git a/libstdc++-v3/include/bits/ranges_util.h b/libstdc++-v3/include/bits/ranges_util.h index 84de258908e..2aa8938edf2 100644 --- a/libstdc++-v3/include/bits/ranges_util.h +++ b/libstdc++-v3/include/bits/ranges_util.h @@ -761,7 +761,7 @@ namespace ranges auto __first = ranges::begin(__r); auto __last = ranges::end(__r); __glibcxx_assert(__first != __last); - auto __result = *__first; + range_value_t<_Range> __result(*__first); while (++__first != __last) { auto&& __tmp = *__first; -- 2.47.3