From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 488BB3858C62 for ; Thu, 3 Nov 2022 11:41:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 488BB3858C62 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667475716; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=I7Djw6zn9pJytJ4+Yw/wxhue5BXy387HAugtPi+mr9I=; b=EwCUyLj4/8Rc6Uv6MQEC6rJQeXbfxNsw2APcjoBO83TjXcMe6sxR2I/OJSjdaC5j8Uz+M7 1MKinQKnJg8ckDNEi8oqj9klqQCsmyqhag+Aj9i8PqfTnEHq/SC+NIutPSPrF72QE+8bos gQlsCqxNx7pAYIqnDQEa/+BeFlD2TeI= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-120-ZhumKDVgNsWYkxOAzMX9cQ-1; Thu, 03 Nov 2022 07:41:54 -0400 X-MC-Unique: ZhumKDVgNsWYkxOAzMX9cQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CE9BB29A8AEC; Thu, 3 Nov 2022 11:41:53 +0000 (UTC) Received: from localhost (unknown [10.33.37.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 98E5839D7C; Thu, 3 Nov 2022 11:41:53 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Add missing move in ranges::copy Date: Thu, 3 Nov 2022 11:41:52 +0000 Message-Id: <20221103114152.708336-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Tested x86_64-linux. Pushed to trunk. -- >8 -- 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. --- libstdc++-v3/include/bits/ranges_algobase.h | 2 +- .../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(); } -- 2.38.1