From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 198E33858D3C; Thu, 3 Nov 2022 11:32:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 198E33858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667475178; bh=FxpIT8o9Jn+FAy7k+3l3B/TGxFAWLbkyhyWdbhN8zVA=; h=From:To:Subject:Date:From; b=wE8FNHQAS6+LWNmmSaT8aSde21HsYQ4N9I78mfty5pCvJpENZvJ/T27OF9iY34ElR z6gWDeZtm58maSJmOuybY99qCrMXDTwuNfEtyybWBa9+SGjBdK93VsnpkB5sZtKPGs P3AqY9WVfbhOz2RC3DsYRtbDEEkSBqBLs1/BvDeo= 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 r13-3623] libstdc++: Add missing move in ranges::copy X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: f95e4eced20666a981881f76d66d997922648687 X-Git-Newrev: 2ff0e62275b1c322a8b65f38f8336f37d31c30e4 Message-Id: <20221103113258.198E33858D3C@sourceware.org> Date: Thu, 3 Nov 2022 11:32:58 +0000 (GMT) List-Id: https://gcc.gnu.org/g:2ff0e62275b1c322a8b65f38f8336f37d31c30e4 commit r13-3623-g2ff0e62275b1c322a8b65f38f8336f37d31c30e4 Author: Jonathan Wakely Date: Thu Nov 3 09:17:57 2022 +0000 libstdc++: Add missing move in ranges::copy This is needed to support a move-only output iterator when the input iterators are specializations of __normal_iterator. libstdc++-v3/ChangeLog: * include/bits/ranges_algobase.h (__detail::__copy_or_move): Move output iterator. * testsuite/25_algorithms/copy/constrained.cc: Check copying to move-only output iterator. Diff: --- libstdc++-v3/include/bits/ranges_algobase.h | 2 +- .../testsuite/25_algorithms/copy/constrained.cc | 24 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/bits/ranges_algobase.h b/libstdc++-v3/include/bits/ranges_algobase.h index f6f0b9c83b0..443ad52ecc6 100644 --- a/libstdc++-v3/include/bits/ranges_algobase.h +++ b/libstdc++-v3/include/bits/ranges_algobase.h @@ -239,7 +239,7 @@ namespace ranges { auto [__in,__out] = ranges::__copy_or_move<_IsMove>(__first.base(), __last.base(), - __result); + std::move(__result)); return {decltype(__first){__in}, std::move(__out)}; } else if constexpr (__is_normal_iterator<_Out>) diff --git a/libstdc++-v3/testsuite/25_algorithms/copy/constrained.cc b/libstdc++-v3/testsuite/25_algorithms/copy/constrained.cc index 98f038a6c5f..444dfa78894 100644 --- a/libstdc++-v3/testsuite/25_algorithms/copy/constrained.cc +++ b/libstdc++-v3/testsuite/25_algorithms/copy/constrained.cc @@ -226,6 +226,29 @@ test06() VERIFY( ranges::equal(v, (int[]){1,2,3,0}) ); } +void +test07() +{ + struct move_only_output_iterator + { + using value_type = int; + using difference_type = short; + using iterator_category = std::output_iterator_tag; + + move_only_output_iterator() = default; + move_only_output_iterator(move_only_output_iterator&&) = default; + move_only_output_iterator& operator=(move_only_output_iterator&&) = default; + + move_only_output_iterator& operator*() { return *this; } + move_only_output_iterator& operator++() { return *this; } + move_only_output_iterator operator++(int) { return std::move(*this); } + + void operator=(int) { } + }; + + ranges::copy(std::vector{1,2,3}, move_only_output_iterator{}); +} + int main() { @@ -235,4 +258,5 @@ main() test04(); static_assert(test05()); test06(); + test07(); }