https://gcc.gnu.org/g:ccd150e0f45a8d7b622052b89b1d9b26d96d2476
commit r14-12705-gccd150e0f45a8d7b622052b89b1d9b26d96d2476 Author: Patrick Palka <[email protected]> Date: Tue Jul 1 13:43:09 2025 -0400 libstdc++: Use ranges::iter_move in ranges::unique [PR120789] PR libstdc++/120789 libstdc++-v3/ChangeLog: * include/bits/ranges_algo.h (__unique_fn::operator()): Use ranges::iter_move(iter) instead of std::move(*iter). * testsuite/25_algorithms/unique/120789.cc: New test. Reviewed-by: Tomasz KamiĆski <[email protected]> Reviewed-by: Jonathan Wakely <[email protected]> (cherry picked from commit 6f69a68998f601cdb86c65113eb1feddfa9da31a) Diff: --- libstdc++-v3/include/bits/ranges_algo.h | 2 +- .../testsuite/25_algorithms/unique/120789.cc | 36 ++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/bits/ranges_algo.h b/libstdc++-v3/include/bits/ranges_algo.h index 59374e3dbd0c..f8168e6a7ff4 100644 --- a/libstdc++-v3/include/bits/ranges_algo.h +++ b/libstdc++-v3/include/bits/ranges_algo.h @@ -1144,7 +1144,7 @@ namespace ranges if (!std::__invoke(__comp, std::__invoke(__proj, *__dest), std::__invoke(__proj, *__first))) - *++__dest = std::move(*__first); + *++__dest = ranges::iter_move(__first); return {++__dest, __first}; } diff --git a/libstdc++-v3/testsuite/25_algorithms/unique/120789.cc b/libstdc++-v3/testsuite/25_algorithms/unique/120789.cc new file mode 100644 index 000000000000..24b107132473 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/unique/120789.cc @@ -0,0 +1,36 @@ +// PR libstdc++/120789 - ranges::unique should use ranges::iter_move +// { dg-do compile { target c++20 } } + +#include <algorithm> + +struct A +{ + bool operator==(const A&) const; +}; + +struct B +{ + B(B&&) = delete; + B& operator=(const A&) const; + + operator A() const; + bool operator==(const B&) const; +}; + +struct I +{ + using value_type = A; + using difference_type = int; + B operator*() const; + I& operator++(); + I operator++(int); + bool operator==(const I&) const; + friend A iter_move(const I&); +}; + +void +test01() +{ + std::ranges::subrange<I, I> r; + auto [begin, end] = std::ranges::unique(r); +}
