From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id A25F43858C27; Wed, 13 Oct 2021 13:56:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A25F43858C27 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r10-10210] libstdc++: Fix various bugs in ranges_algo.h [PR100187, ...] X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: a0865d33b293bd0a949562dd6e73f097a767a40e X-Git-Newrev: 139bafaaba0c775ca65712621bd60e079b488d73 Message-Id: <20211013135651.A25F43858C27@sourceware.org> Date: Wed, 13 Oct 2021 13:56:51 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Oct 2021 13:56:51 -0000 https://gcc.gnu.org/g:139bafaaba0c775ca65712621bd60e079b488d73 commit r10-10210-g139bafaaba0c775ca65712621bd60e079b488d73 Author: Patrick Palka Date: Tue Apr 27 23:21:19 2021 -0400 libstdc++: Fix various bugs in ranges_algo.h [PR100187, ...] This fixes some bugs with our ranges algorithms in uncommon situations, such as when the return type of a predicate is a non-copyable class type that's implicitly convertible to bool (PR100187), when a comparison predicate isn't invocable as an rvalue (PR100237), and when the return type of a projection function is non-copyable (PR100249). This also fixes PR100287, which reports that we're moving __first twice when constructing with it an empty subrange in ranges::partition. libstdc++-v3/ChangeLog: PR libstdc++/100187 PR libstdc++/100237 PR libstdc++/100249 PR libstdc++/100287 * include/bits/ranges_algo.h (__search_n_fn::operator()): Give the __value_comp lambda an explicit bool return type. (__is_permutation_fn::operator()): Give the __proj_scan local variable auto&& return type. Give the __comp_scan lambda an explicit bool return type. (__remove_fn::operator()): Give the __pred lambda an explicit bool return type. (__partition_fn::operator()): Don't std::move __first twice when returning an empty subrange. (__min_fn::operator()): Don't std::move __comp. (__max_fn::operator()): Likewise. (__minmax_fn::operator()): Likewise. (cherry picked from commit d91e7eab3a2c3957c2220ad71e62d9fc78cccb9b) Diff: --- libstdc++-v3/include/bits/ranges_algo.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libstdc++-v3/include/bits/ranges_algo.h b/libstdc++-v3/include/bits/ranges_algo.h index 45379d1cb9c..2774afb2dd1 100644 --- a/libstdc++-v3/include/bits/ranges_algo.h +++ b/libstdc++-v3/include/bits/ranges_algo.h @@ -561,7 +561,7 @@ namespace ranges if (__count <= 0) return {__first, __first}; - auto __value_comp = [&] (_Rp&& __arg) { + auto __value_comp = [&] (_Rp&& __arg) -> bool { return std::__invoke(__pred, std::forward<_Rp>(__arg), __value); }; if (__count == 1) @@ -804,8 +804,8 @@ namespace ranges for (auto __scan = __first1; __scan != __last1; ++__scan) { - auto __proj_scan = std::__invoke(__proj1, *__scan); - auto __comp_scan = [&] (_Tp&& __arg) { + auto&& __proj_scan = std::__invoke(__proj1, *__scan); + auto __comp_scan = [&] (_Tp&& __arg) -> bool { return std::__invoke(__pred, __proj_scan, std::forward<_Tp>(__arg)); }; @@ -1255,7 +1255,7 @@ namespace ranges operator()(_Iter __first, _Sent __last, const _Tp& __value, _Proj __proj = {}) const { - auto __pred = [&] (auto&& __arg) { + auto __pred = [&] (auto&& __arg) -> bool { return std::forward(__arg) == __value; }; return ranges::remove_if(__first, __last, @@ -2538,11 +2538,11 @@ namespace ranges else { if (__first == __last) - return {std::move(__first), std::move(__first)}; + return {__first, __first}; while (std::__invoke(__pred, std::__invoke(__proj, *__first))) if (++__first == __last) - return {std::move(__first), std::move(__first)}; + return {__first, __first}; auto __next = __first; while (++__next != __last) @@ -3119,7 +3119,7 @@ namespace ranges operator()(const _Tp& __a, const _Tp& __b, _Comp __comp = {}, _Proj __proj = {}) const { - if (std::__invoke(std::move(__comp), + if (std::__invoke(__comp, std::__invoke(__proj, __b), std::__invoke(__proj, __a))) return __b; @@ -3173,7 +3173,7 @@ namespace ranges operator()(const _Tp& __a, const _Tp& __b, _Comp __comp = {}, _Proj __proj = {}) const { - if (std::__invoke(std::move(__comp), + if (std::__invoke(__comp, std::__invoke(__proj, __a), std::__invoke(__proj, __b))) return __b; @@ -3273,7 +3273,7 @@ namespace ranges operator()(const _Tp& __a, const _Tp& __b, _Comp __comp = {}, _Proj __proj = {}) const { - if (std::__invoke(std::move(__comp), + if (std::__invoke(__comp, std::__invoke(__proj, __b), std::__invoke(__proj, __a))) return {__b, __a};