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

            Bug ID: 120822
           Summary: bad warn -Wredundant-move on return std::move
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rockeet at gmail dot com
  Target Milestone: ---

#include <memory>
struct A { int a = 0; };
struct B : A {};
A fa() {
        B b;
        return std::move(b); // 1. should not warn
}
B fb() {
        B b;
        return std::move(b); // 2. should warn
}
int main() {
        A a = fa();
        B b = fb();
        return 0;
}

1. object type does not exact match return type, std::move is not redundant.
2. object type exact match return type, std::move is redundant.

g++-13 & g++-14 does not warn at 2 but warns at 1:

warning: redundant move in return statement [-Wredundant-move]

Reply via email to