]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++/ranges: Fix more wrong value type init from reference type [PR111861]
authorPatrick Palka <ppalka@redhat.com>
Wed, 17 Sep 2025 18:14:37 +0000 (14:14 -0400)
committerPatrick Palka <ppalka@redhat.com>
Wed, 17 Sep 2025 18:14:37 +0000 (14:14 -0400)
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 <jwakely@redhat.com>
libstdc++-v3/include/bits/ranges_algo.h
libstdc++-v3/include/bits/ranges_util.h

index 4025bba9f2048cc1f7db98d0c6f4467eac2f5c83..5c9fe627aee0d8456c7df17dfab691bbdb586fb7 100644 (file)
@@ -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;
index 84de258908ea33f9b38d092880d26dc2e633b8b6..2aa8938edf25eb70ec15de570f366153cfb3f42e 100644 (file)
@@ -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;