aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/std/numeric
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2024-12-03 16:36:05 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2024-12-03 21:34:26 +0000
commitcd107a6343c96c4ef26096e250d43a4a4211eced (patch)
treec2ea5aa63af2d981be6ae67f76e2f772d482113f /libstdc++-v3/include/std/numeric
parentaa7acf6fc9251cc9bdb9a406dc58439eb54e1217 (diff)
downloadgcc-cd107a6343c96c4ef26096e250d43a4a4211eced.zip
gcc-cd107a6343c96c4ef26096e250d43a4a4211eced.tar.gz
gcc-cd107a6343c96c4ef26096e250d43a4a4211eced.tar.bz2
libstdc++: Fix parallel std::exclusive_scan [PR108236]
The standard says that std::exclusive_scan can be used to work in place, i.e. where the output range is the same as the input range. This means that the first sum cannot be written to the output until after reading the first input value, otherwise we'll already have overwritten the first input value. While writing a new testcase I also realised that the serial version of std::exclusive_scan uses copy construction for the accumulator variable, but the standard only requires Cpp17MoveConstructible. We also require move assignable, which is missing from the standard's requirements, but we should at least use move construction not copy construction. A similar problem exists for some other new C++17 numeric algos, but I'll fix the others in a subsequent commit. libstdc++-v3/ChangeLog: PR libstdc++/108236 * include/pstl/glue_numeric_impl.h (exclusive_scan): Pass __init as rvalue. * include/pstl/numeric_impl.h (__brick_transform_scan): Do not write through __result until after reading through __first. Move __init into return value. (__pattern_transform_scan): Pass __init as rvalue. * include/std/numeric (exclusive_scan): Move construct instead of copy constructing. * testsuite/26_numerics/exclusive_scan/2.cc: New test. * testsuite/26_numerics/pstl/numeric_ops/108236.cc: New test.
Diffstat (limited to 'libstdc++-v3/include/std/numeric')
-rw-r--r--libstdc++-v3/include/std/numeric4
1 files changed, 2 insertions, 2 deletions
diff --git a/libstdc++-v3/include/std/numeric b/libstdc++-v3/include/std/numeric
index dd98f40..37579c5 100644
--- a/libstdc++-v3/include/std/numeric
+++ b/libstdc++-v3/include/std/numeric
@@ -491,8 +491,8 @@ namespace __detail
{
while (__first != __last)
{
- auto __v = __init;
- __init = __binary_op(__init, *__first);
+ _Tp __v = std::move(__init);
+ __init = __binary_op(__v, *__first);
++__first;
*__result++ = std::move(__v);
}