public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Patrick Palka <ppalka@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-178] libstdc++: Fix various bugs in ranges_algo.h [PR100187, ...] Date: Wed, 28 Apr 2021 03:23:28 +0000 (GMT) [thread overview] Message-ID: <20210428032328.19A243857025@sourceware.org> (raw) https://gcc.gnu.org/g:d91e7eab3a2c3957c2220ad71e62d9fc78cccb9b commit r12-178-gd91e7eab3a2c3957c2220ad71e62d9fc78cccb9b Author: Patrick Palka <ppalka@redhat.com> 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. 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 23e6480b9a8..cda3042c11f 100644 --- a/libstdc++-v3/include/bits/ranges_algo.h +++ b/libstdc++-v3/include/bits/ranges_algo.h @@ -562,7 +562,7 @@ namespace ranges if (__count <= 0) return {__first, __first}; - auto __value_comp = [&] <typename _Rp> (_Rp&& __arg) { + auto __value_comp = [&] <typename _Rp> (_Rp&& __arg) -> bool { return std::__invoke(__pred, std::forward<_Rp>(__arg), __value); }; if (__count == 1) @@ -805,8 +805,8 @@ namespace ranges for (auto __scan = __first1; __scan != __last1; ++__scan) { - auto __proj_scan = std::__invoke(__proj1, *__scan); - auto __comp_scan = [&] <typename _Tp> (_Tp&& __arg) { + auto&& __proj_scan = std::__invoke(__proj1, *__scan); + auto __comp_scan = [&] <typename _Tp> (_Tp&& __arg) -> bool { return std::__invoke(__pred, __proj_scan, std::forward<_Tp>(__arg)); }; @@ -1256,7 +1256,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<decltype(__arg)>(__arg) == __value; }; return ranges::remove_if(__first, __last, @@ -2537,11 +2537,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) @@ -3118,7 +3118,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; @@ -3172,7 +3172,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; @@ -3272,7 +3272,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};
reply other threads:[~2021-04-28 3:23 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210428032328.19A243857025@sourceware.org \ --to=ppalka@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).