[Bug libstdc++/108236] std::exclusive_scan with execution policy does not work in-place
cvs-commit at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Mar 31 12:07:13 GMT 2025
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108236
--- Comment #12 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:
https://gcc.gnu.org/g:081989e519b2fa80a36d852af43cdda63b2e1a16
commit r13-9471-g081989e519b2fa80a36d852af43cdda63b2e1a16
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Tue Dec 3 16:36:05 2024 +0000
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.
(cherry picked from commit cd107a6343c96c4ef26096e250d43a4a4211eced)
More information about the Gcc-bugs
mailing list