From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 51BD7385829A; Thu, 8 Feb 2024 21:29:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 51BD7385829A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1707427740; bh=heRoWAQXlwjnc3hb4kOjsLWCwdBFy1aGQA0xecVv0VU=; h=From:To:Subject:Date:From; b=NEugYozqDDm1u76FBXDSvv/Uyv6Fgdk6KwfLm81gp3PqUMgN8XMoTNvHBt0gLDE98 7qbnnkMWIpf3lpRJZFGQW3W4ibF32T/7WCIqN2RvbE3p5fhtfHiZWgK+CWzxIYe3gV dPVTnuC9Fp7sW+5D5HxqqHWTCp6txeRqVelzs5SI= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-10145] libstdc++: Avoid reusing moved-from iterators in PSTL tests [PR90276] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: cc5bf5a8bbcf7775d5e224a7cb7e5bd179ccf784 X-Git-Newrev: 39d37ffbf890334b16ffb56da9fe00f0daa87f16 Message-Id: <20240208212900.51BD7385829A@sourceware.org> Date: Thu, 8 Feb 2024 21:29:00 +0000 (GMT) List-Id: https://gcc.gnu.org/g:39d37ffbf890334b16ffb56da9fe00f0daa87f16 commit r12-10145-g39d37ffbf890334b16ffb56da9fe00f0daa87f16 Author: Jonathan Wakely Date: Wed Jan 31 10:41:49 2024 +0000 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. (cherry picked from commit 723a7c1ad29523b9ddff53c7b147bffea56fbb63) Diff: --- libstdc++-v3/testsuite/util/pstl/test_utils.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libstdc++-v3/testsuite/util/pstl/test_utils.h b/libstdc++-v3/testsuite/util/pstl/test_utils.h index 80a8f9c7b879..9991f37d7eee 100644 --- a/libstdc++-v3/testsuite/util/pstl/test_utils.h +++ b/libstdc++-v3/testsuite/util/pstl/test_utils.h @@ -1007,18 +1007,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...); } };