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

            Bug ID: 100387
           Summary: ranges::minmax compares moved-out value
           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: ---

In ranges_algo.h#L3301:

  if (std::__invoke(__comp,
                    std::__invoke(__proj, __tmp),
                    std::__invoke(__proj, __result.min)))
    __result.min = std::move(__tmp);
  if (!(bool)std::__invoke(__comp,
                           std::__invoke(__proj, __tmp),
                           std::__invoke(__proj, __result.max)))
    __result.max = std::move(__tmp);

we compare the moved-out __tmp in the second if statement.
test: https://godbolt.org/z/W6WTG6sdG

Reply via email to