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