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

            Bug ID: 90428
           Summary: -Wredundant-move could warn for more cases
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
                CC: mpolacek at gcc dot gnu.org
  Target Milestone: ---

G++ gives no warnings for this:

#include <utility>

struct T { };

T f(const T& t)
{
  return std::move(t);
}

T g()
{
  return std::move(f());
}

The std::move in f does nothing, because the argument is const (and T does not
have a T(const T&&) constructor, so the conversion to an rvalue is useless).

The std::move in g also does nothing, because the argument is already an rvalue
(this might actually be a candidate for -Wpessimizing-move instead, since it
prevents elision).

Reply via email to