[libcxx-commits] [libcxx] a70ce8c - [libc++][PSTL] Fix double-move in std::transform_reduce
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jul 12 08:56:18 PDT 2023
Author: Nikolas Klauser
Date: 2023-07-12T08:56:10-07:00
New Revision: a70ce8cb0e4b45841726347c723147af591b054a
URL: https://github.com/llvm/llvm-project/commit/a70ce8cb0e4b45841726347c723147af591b054a
DIFF: https://github.com/llvm/llvm-project/commit/a70ce8cb0e4b45841726347c723147af591b054a.diff
LOG: [libc++][PSTL] Fix double-move in std::transform_reduce
Reviewed By: #libc, ldionne
Spies: h-vetinari, libcxx-commits
Differential Revision: https://reviews.llvm.org/D154913
Added:
Modified:
libcxx/include/__algorithm/pstl_backends/cpu_backends/transform_reduce.h
libcxx/test/std/algorithms/numeric.ops/transform.reduce/pstl.transform_reduce.unary.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/include/__algorithm/pstl_backends/cpu_backends/transform_reduce.h b/libcxx/include/__algorithm/pstl_backends/cpu_backends/transform_reduce.h
index 9b7203b3542f11..09e4ffce9e2927 100644
--- a/libcxx/include/__algorithm/pstl_backends/cpu_backends/transform_reduce.h
+++ b/libcxx/include/__algorithm/pstl_backends/cpu_backends/transform_reduce.h
@@ -163,7 +163,7 @@ _LIBCPP_HIDE_FROM_ABI _Tp __pstl_transform_reduce(
std::move(__last),
[__transform](_ForwardIterator __iter) { return __transform(*__iter); },
std::move(__init),
- std::move(__reduce),
+ __reduce,
[=](_ForwardIterator __brick_first, _ForwardIterator __brick_last, _Tp __brick_init) {
return std::__pstl_transform_reduce<__remove_parallel_policy_t<_ExecutionPolicy>>(
__cpu_backend_tag{},
diff --git a/libcxx/test/std/algorithms/numeric.ops/transform.reduce/pstl.transform_reduce.unary.pass.cpp b/libcxx/test/std/algorithms/numeric.ops/transform.reduce/pstl.transform_reduce.unary.pass.cpp
index 11a678b1ac6eb4..a32a4f85f63341 100644
--- a/libcxx/test/std/algorithms/numeric.ops/transform.reduce/pstl.transform_reduce.unary.pass.cpp
+++ b/libcxx/test/std/algorithms/numeric.ops/transform.reduce/pstl.transform_reduce.unary.pass.cpp
@@ -20,6 +20,7 @@
// T init, BinaryOperation binary_op, UnaryOperation unary_op);
#include <numeric>
+#include <string>
#include <vector>
#include "MoveOnly.h"
@@ -42,8 +43,14 @@ struct Test {
Iter1(std::data(a)),
Iter1(std::data(a) + std::size(a)),
ValueT(34),
- [](ValueT i, ValueT j) { return i + j; },
- [](ValueT i) { return i + 1; });
+ [check = std::string("Banane")](ValueT i, ValueT j) {
+ assert(check == "Banane"); // ensure that no double-moves happen
+ return i + j;
+ },
+ [check = std::string("Banane")](ValueT i) {
+ assert(check == "Banane"); // ensure that no double-moves happen
+ return i + 1;
+ });
static_assert(std::is_same_v<decltype(ret), ValueT>);
assert(ret == expected);
}
More information about the libcxx-commits
mailing list