https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120822
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The spec says that `return `b;` treats b as an rvalue, and it has said that
since C++17.
So std::move(b) is redundant, the warning is correct.
If you want a warning for the fb() case then use -Wpessimizing-move (or -Wall)
which is a separate warning from -Wredundant-move.
move.cc: In function ‘A fa()’:
move.cc:6:25: warning: redundant move in return statement [-Wredundant-move]
6 | return std::move(b); // 1. should not warn
| ~~~~~~~~~^~~
move.cc:6:25: note: remove ‘std::move’ call
move.cc: In function ‘B fb()’:
move.cc:10:25: warning: moving a local object in a return statement prevents
copy elision [-Wpessimizing-move]
10 | return std::move(b); // 2. should warn
| ~~~~~~~~~^~~
move.cc:10:25: note: remove ‘std::move’ call
I don't see any GCC bug here.