From: Jonathan Wakely Date: Wed, 31 Jan 2024 10:41:49 +0000 (+0000) Subject: libstdc++: Avoid reusing moved-from iterators in PSTL tests [PR90276] X-Git-Tag: basepoints/gcc-15~1396 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=723a7c1ad29523b9ddff53c7b147bffea56fbb63;p=thirdparty%2Fgcc.git libstdc++: Avoid reusing moved-from iterators in PSTL tests [PR90276] The reverse_invoker utility for PSTL tests uses forwarding references for all parameters, but some of those parameters get forwarded to move constructors which then leave the objects in a moved-from state. When the parameters are forwarded a second time that results in making new copies of moved-from iterators. For libstdc++ debug mode iterators, the moved-from state is singular, which means copying them will abort at runtime. The fix is to make copies of iterator arguments instead of forwarding them. The callers of reverse_invoker::operator() also forward the iterators multiple times, but that's OK because reverse_invoker accepts them by forwarding reference but then breaks the chain of forwarding and copies them as lvalues. libstdc++-v3/ChangeLog: PR libstdc++/90276 * testsuite/util/pstl/test_utils.h (reverse_invoker): Do not use perfect forwarding for iterator arguments. --- diff --git a/libstdc++-v3/testsuite/util/pstl/test_utils.h b/libstdc++-v3/testsuite/util/pstl/test_utils.h index ed6d48b9471a..e35084eabb20 100644 --- a/libstdc++-v3/testsuite/util/pstl/test_utils.h +++ b/libstdc++-v3/testsuite/util/pstl/test_utils.h @@ -1083,18 +1083,18 @@ struct iterator_invoker template struct reverse_invoker { - template + template void - operator()(Rest&&... rest) + operator()(Policy&& exec, Op op, Rest&&... rest) { // Random-access iterator - iterator_invoker()(std::forward(rest)...); + iterator_invoker()(std::forward(exec), op, rest...); // Forward iterator - iterator_invoker()(std::forward(rest)...); + iterator_invoker()(std::forward(exec), op, rest...); // Bidirectional iterator - iterator_invoker()(std::forward(rest)...); + iterator_invoker()(std::forward(exec), op, rest...); } };