public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/100237] New: Unnecessary std::move in ranges::min, ranges::max and ranges::minmax
@ 2021-04-23 17:28 hewillk at gmail dot com
  2021-04-23 19:09 ` [Bug libstdc++/100237] " ppalka at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: hewillk at gmail dot com @ 2021-04-23 17:28 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100237
           Summary: Unnecessary std::move in ranges::min, ranges::max and
                    ranges::minmax
           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_algo.h#L3121:

constexpr const _Tp&
operator()(const _Tp& __a, const _Tp& __b,
           _Comp __comp = {}, _Proj __proj = {}) const
{
  if (std::__invoke(std::move(__comp),
                    std::__invoke(__proj, __b),
                    std::__invoke(__proj, __a)))
    return __b;
  else
    return __a;
}

Although it is unclear why there is a std::move in ranges::min, ranges::max,
and ranges::minmax, it is obviously unnecessary and will lead to the following
valid code failed:

#include <algorithm>

struct Comp {
  constexpr bool operator()(int, int) & { return true; };
} comp;

static_assert(        std::min(0, 1, comp));
static_assert(std::ranges::min(0, 1, comp));

static_assert(        std::max(0, 1, comp));
static_assert(std::ranges::max(0, 1, comp));

static_assert(        std::minmax(0, 1, comp).first);
static_assert(std::ranges::minmax(0, 1, comp).min);

https://godbolt.org/z/MbG8zbcGY

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

end of thread, other threads:[~2021-10-13 13:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-23 17:28 [Bug libstdc++/100237] New: Unnecessary std::move in ranges::min, ranges::max and ranges::minmax hewillk at gmail dot com
2021-04-23 19:09 ` [Bug libstdc++/100237] " ppalka at gcc dot gnu.org
2021-04-28  3:23 ` cvs-commit at gcc dot gnu.org
2021-10-13 13:51 ` cvs-commit at gcc dot gnu.org
2021-10-13 13:56 ` cvs-commit at gcc dot gnu.org
2021-10-13 13:58 ` ppalka at gcc dot gnu.org

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