aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2025-07-01 13:43:12 -0400
committerPatrick Palka <ppalka@redhat.com>2025-07-01 13:43:12 -0400
commit17e9ae215f991f2f94fe480aee2404c508388b7c (patch)
treedb80aa459db8ac191522f0acbb27cc2b06324664
parent6f69a68998f601cdb86c65113eb1feddfa9da31a (diff)
downloadgcc-17e9ae215f991f2f94fe480aee2404c508388b7c.zip
gcc-17e9ae215f991f2f94fe480aee2404c508388b7c.tar.gz
gcc-17e9ae215f991f2f94fe480aee2404c508388b7c.tar.bz2
libstdc++: Use ranges::iter_move in ranges::remove_if [PR120789]
PR libstdc++/120789 libstdc++-v3/ChangeLog: * include/bits/ranges_algo.h (__remove_if_fn::operator()): Use ranges::iter_move(iter) instead of std::move(*iter). * testsuite/25_algorithms/remove_if/120789.cc: New test. Reviewed-by: Tomasz KamiƄski <tkaminsk@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
-rw-r--r--libstdc++-v3/include/bits/ranges_algo.h2
-rw-r--r--libstdc++-v3/testsuite/25_algorithms/remove_if/120789.cc36
2 files changed, 37 insertions, 1 deletions
diff --git a/libstdc++-v3/include/bits/ranges_algo.h b/libstdc++-v3/include/bits/ranges_algo.h
index 7aea5c9..cf369c5 100644
--- a/libstdc++-v3/include/bits/ranges_algo.h
+++ b/libstdc++-v3/include/bits/ranges_algo.h
@@ -1294,7 +1294,7 @@ namespace ranges
for (; __first != __last; ++__first)
if (!std::__invoke(__pred, std::__invoke(__proj, *__first)))
{
- *__result = std::move(*__first);
+ *__result = ranges::iter_move(__first);
++__result;
}
diff --git a/libstdc++-v3/testsuite/25_algorithms/remove_if/120789.cc b/libstdc++-v3/testsuite/25_algorithms/remove_if/120789.cc
new file mode 100644
index 0000000..c1f4eeb
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/remove_if/120789.cc
@@ -0,0 +1,36 @@
+// PR libstdc++/120789 - ranges::remove_if 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::remove_if(r, [](auto&&) { return true; });
+}