public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/100249] New: missing forwarding std::__invoke result in ranges::is_permutation and ranges::clamp
@ 2021-04-24 18:33 hewillk at gmail dot com
  2021-04-25  5:54 ` [Bug libstdc++/100249] " hewillk at gmail dot com
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: hewillk at gmail dot com @ 2021-04-24 18:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100249

            Bug ID: 100249
           Summary: missing forwarding std::__invoke result in
                    ranges::is_permutation and ranges::clamp
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hewillk at gmail dot com
  Target Milestone: ---

Hey, in ranges::is_permutation in ranges_algo.h#L808:

    auto __proj_scan = std::__invoke(__proj1, *__scan);
    auto __comp_scan = [&] <typename _Tp> (_Tp&& __arg) {
      return std::__invoke(__pred, __proj_scan,
                           std::forward<_Tp>(__arg));
    };

the __proj_scan seems to forget to use auto&& to receive the std::__ invoke
call, which will cause compile failure if the return type is non-copyable:
https://godbolt.org/z/WaKc7bWM4

also, we should perfect forward the type of __proj_scan to the next
std::__invoke call, and ranges::clamp in ranges_algo.h#L3232 has the same
issue:

    auto&& __proj_val = std::__invoke(__proj, __val);
    if (std::__invoke(__comp, __proj_val, std::__invoke(__proj, __lo)))
      return __lo;

when the type of __proj_val is an rvalue reference, we need to convert it to
rvalue for the next std::__invoke call: https://godbolt.org/z/1G7aqxs3c.

So I think it should be relatively safe to inline all std::__invoke calls.

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2023-08-20  3:24 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-24 18:33 [Bug libstdc++/100249] New: missing forwarding std::__invoke result in ranges::is_permutation and ranges::clamp hewillk at gmail dot com
2021-04-25  5:54 ` [Bug libstdc++/100249] " hewillk at gmail dot com
2021-04-26 12:39 ` ppalka at gcc dot gnu.org
2021-04-27 15:38 ` ppalka at gcc dot gnu.org
2021-04-27 15:43 ` ppalka at gcc dot gnu.org
2021-04-28  1:27 ` hewillk at gmail dot com
2021-04-28  3:15 ` ppalka at gcc dot gnu.org
2021-04-28  3:23 ` cvs-commit at gcc dot gnu.org
2021-05-08  2:24 ` hewillk at gmail dot com
2021-05-11 16:36 ` ppalka at gcc dot gnu.org
2021-10-13 13:52 ` cvs-commit at gcc dot gnu.org
2021-10-13 13:56 ` cvs-commit at gcc dot gnu.org
2021-11-23 16:52 ` redi at gcc dot gnu.org
2023-08-20  3:24 ` de34 at live dot cn

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).