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 ESMTP id 4B07A3893664 for ; Mon, 26 Jul 2021 09:49:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4B07A3893664 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-470-Ey9nWQVVOFW-8id-UMIkUw-1; Mon, 26 Jul 2021 05:49:38 -0400 X-MC-Unique: Ey9nWQVVOFW-8id-UMIkUw-1 Received: by mail-wm1-f70.google.com with SMTP id j204-20020a1c23d50000b029024e75a15714so2517808wmj.0 for ; Mon, 26 Jul 2021 02:49:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ZlQycrtMc1vWY4zLLe81FUI2laBL3rMe/pGAJ5IVYis=; b=BMmZDtyOkhoeH572rDZOmJJIE8b23JfwCeFkCCMbqpTnsc1IUhb6hRe7qWekoMy1ux gVHL0ulrhkJr1X5PufZbxhsxxeJRZmpv2AqCo93cmeEGAvY8y7eE3NL4JwJheP/3BxtD 9P9LK1uFUbGTkj54u9MJOoFWHphP1TqLa2+iRh4R7ZXpnvcnaSKQuG52qheqtFh37BC9 ws1CjBHY14wrv8GNqvsXbJDgudefz6OLORJARca8Yuk1IUZwu5QkxShtYKjOFCzP8Hxb 5+WNq2w3DBO2x8rm/HwMXrcdujFdAAaBQyjSurUi5g+iU+F1QddUu+peYz/PrGZaAZVO 6EuQ== X-Gm-Message-State: AOAM532RQObA4oFyvb62Icis0hIT0dP7/JAc4trh++VcB7cCuoMkyq2D XHI7rsR2WKIQRWVJhcfuMHxX9n2s+u55gp3puvIZpk4BBlbp4yp6nXwNcvlLUNUPSWZkciu+3VP Hxl0zKB9W3F4u9XBnJjMgf6dFonlyHXt/yQ== X-Received: by 2002:adf:e7c6:: with SMTP id e6mr18213908wrn.221.1627292977281; Mon, 26 Jul 2021 02:49:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvi85DcoP5J1c85RPQQ+UeX3jF3ueZBW8f7kF7k1kQqutoBGebFEsn5Rs7hd3/8l+BV56UVF4JShrptKoKTmE= X-Received: by 2002:adf:e7c6:: with SMTP id e6mr18213894wrn.221.1627292977095; Mon, 26 Jul 2021 02:49:37 -0700 (PDT) MIME-Version: 1.0 References: <20210723163448.3293782-1-ppalka@redhat.com> In-Reply-To: <20210723163448.3293782-1-ppalka@redhat.com> From: Jonathan Wakely Date: Mon, 26 Jul 2021 10:49:26 +0100 Message-ID: Subject: Re: [PATCH] libstdc++: Add missing std::move in ranges::copy/move/reverse_copy [PR101599] To: Patrick Palka Cc: gcc Patches , "libstdc++" X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-13.2 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_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Jul 2021 09:49:43 -0000 On Fri, 23 Jul 2021 at 17:39, Patrick Palka via Libstdc++ wrote: > > In passing, this also renames the template parameter _O2 to _Out2 in > ranges::partition_copy and uglify its function parameters out_true > and out_false. > > Tested on x86_64-pc-linux-gnu, does this look OK for trunk+branches? Yes, thanks. > PR libstdc++/101599 > > libstdc++-v3/ChangeLog: > > * include/bits/ranges_algo.h (__reverse_copy_fn::operator()): > Add missing std::move in return statement. > (__partition_copy_fn::operator()): Rename templtae parameter > _O2 to _Out2. Uglify function parameters out_true and out_false. > * include/bits/ranges_algobase.h (__copy_or_move): Add missing > std::move to recursive call that unwraps a __normal_iterator > output iterator. > * testsuite/25_algorithms/copy/constrained.cc (test06): New test. > * testsuite/25_algorithms/move/constrained.cc (test05): New test. > --- > libstdc++-v3/include/bits/ranges_algo.h | 20 +++++++++---------- > libstdc++-v3/include/bits/ranges_algobase.h | 2 +- > .../25_algorithms/copy/constrained.cc | 13 ++++++++++++ > .../25_algorithms/move/constrained.cc | 13 ++++++++++++ > 4 files changed, 37 insertions(+), 11 deletions(-) > > diff --git a/libstdc++-v3/include/bits/ranges_algo.h b/libstdc++-v3/include/bits/ranges_algo.h > index 83371a4bdf0..8462521c369 100644 > --- a/libstdc++-v3/include/bits/ranges_algo.h > +++ b/libstdc++-v3/include/bits/ranges_algo.h > @@ -1343,7 +1343,7 @@ namespace ranges > *__result = *__tail; > ++__result; > } > - return {__i, __result}; > + return {__i, std::move(__result)}; > } > > template > @@ -2423,14 +2423,14 @@ namespace ranges > struct __partition_copy_fn > { > template _Sent, > - weakly_incrementable _Out1, weakly_incrementable _O2, > + weakly_incrementable _Out1, weakly_incrementable _Out2, > typename _Proj = identity, > indirect_unary_predicate> _Pred> > requires indirectly_copyable<_Iter, _Out1> > - && indirectly_copyable<_Iter, _O2> > - constexpr partition_copy_result<_Iter, _Out1, _O2> > + && indirectly_copyable<_Iter, _Out2> > + constexpr partition_copy_result<_Iter, _Out1, _Out2> > operator()(_Iter __first, _Sent __last, > - _Out1 __out_true, _O2 __out_false, > + _Out1 __out_true, _Out2 __out_false, > _Pred __pred, _Proj __proj = {}) const > { > for (; __first != __last; ++__first) > @@ -2450,18 +2450,18 @@ namespace ranges > } > > template - weakly_incrementable _O2, > + weakly_incrementable _Out2, > typename _Proj = identity, > indirect_unary_predicate, _Proj>> > _Pred> > requires indirectly_copyable, _Out1> > - && indirectly_copyable, _O2> > - constexpr partition_copy_result, _Out1, _O2> > - operator()(_Range&& __r, _Out1 out_true, _O2 out_false, > + && indirectly_copyable, _Out2> > + constexpr partition_copy_result, _Out1, _Out2> > + operator()(_Range&& __r, _Out1 __out_true, _Out2 __out_false, > _Pred __pred, _Proj __proj = {}) const > { > return (*this)(ranges::begin(__r), ranges::end(__r), > - std::move(out_true), std::move(out_false), > + std::move(__out_true), std::move(__out_false), > std::move(__pred), std::move(__proj)); > } > }; > diff --git a/libstdc++-v3/include/bits/ranges_algobase.h b/libstdc++-v3/include/bits/ranges_algobase.h > index c1037657c4c..78c295981d5 100644 > --- a/libstdc++-v3/include/bits/ranges_algobase.h > +++ b/libstdc++-v3/include/bits/ranges_algobase.h > @@ -244,7 +244,7 @@ namespace ranges > else if constexpr (__is_normal_iterator<_Out>) > { > auto [__in,__out] > - = ranges::__copy_or_move<_IsMove>(__first, __last, __result.base()); > + = ranges::__copy_or_move<_IsMove>(std::move(__first), __last, __result.base()); > return {std::move(__in), decltype(__result){__out}}; > } > else if constexpr (sized_sentinel_for<_Sent, _Iter>) > diff --git a/libstdc++-v3/testsuite/25_algorithms/copy/constrained.cc b/libstdc++-v3/testsuite/25_algorithms/copy/constrained.cc > index 77ecf99d5b1..a05948a49c6 100644 > --- a/libstdc++-v3/testsuite/25_algorithms/copy/constrained.cc > +++ b/libstdc++-v3/testsuite/25_algorithms/copy/constrained.cc > @@ -26,6 +26,7 @@ > using __gnu_test::test_container; > using __gnu_test::test_range; > using __gnu_test::input_iterator_wrapper; > +using __gnu_test::input_iterator_wrapper_nocopy; > using __gnu_test::output_iterator_wrapper; > using __gnu_test::forward_iterator_wrapper; > > @@ -214,6 +215,17 @@ test05() > return ok; > } > > +void > +test06() > +{ > + // PR libstdc++/101599 > + int x[] = {1,2,3}; > + test_range rx(x); > + std::vector v(4, 0); > + ranges::copy(rx, v.begin()); > + VERIFY( ranges::equal(v, (int[]){1,2,3,0}) ); > +} > + > int > main() > { > @@ -222,4 +234,5 @@ main() > static_assert(test03()); > test04(); > static_assert(test05()); > + test06(); > } > diff --git a/libstdc++-v3/testsuite/25_algorithms/move/constrained.cc b/libstdc++-v3/testsuite/25_algorithms/move/constrained.cc > index 1cdfbdf23bc..2ce27b663a2 100644 > --- a/libstdc++-v3/testsuite/25_algorithms/move/constrained.cc > +++ b/libstdc++-v3/testsuite/25_algorithms/move/constrained.cc > @@ -26,6 +26,7 @@ > using __gnu_test::test_container; > using __gnu_test::test_range; > using __gnu_test::input_iterator_wrapper; > +using __gnu_test::input_iterator_wrapper_nocopy; > using __gnu_test::output_iterator_wrapper; > using __gnu_test::forward_iterator_wrapper; > > @@ -193,6 +194,17 @@ test04() > VERIFY( ranges::count(y, 0, &X::moved) == 6 ); > } > > +void > +test05() > +{ > + // PR libstdc++/101599 > + int x[] = {1,2,3}; > + test_range rx(x); > + std::vector v(4, 0); > + ranges::move(rx, v.begin()); > + VERIFY( ranges::equal(v, (int[]){1,2,3,0}) ); > +} > + > int > main() > { > @@ -200,4 +212,5 @@ main() > test02(); > static_assert(test03()); > test04(); > + test05(); > } > -- > 2.32.0.349.gdaab8a564f >