Similarly to 86981, we could also warn here about the redundant (but not pessimizing) move here: #include <utility> struct S { }; S foo (S s) { return std::move (s); } the compiler will try a move operation regardless the std::move (if the move ctor is present and accessible). Unless the parameter is const, of course.
This should be a fairly easy extension of -Wpessimizing-move.
See also: bug 67906 and bug 81159
Author: mpolacek Date: Sun Aug 26 16:45:51 2018 New Revision: 263863 URL: https://gcc.gnu.org/viewcvs?rev=263863&root=gcc&view=rev Log: PR c++/87029, Implement -Wredundant-move. * c.opt (Wredundant-move): New option. * typeck.c (treat_lvalue_as_rvalue_p): New function. (maybe_warn_pessimizing_move): Call convert_from_reference. Warn about redundant moves. * doc/invoke.texi: Document -Wredundant-move. * g++.dg/cpp0x/Wredundant-move1.C: New test. * g++.dg/cpp0x/Wredundant-move2.C: New test. * g++.dg/cpp0x/Wredundant-move3.C: New test. * g++.dg/cpp0x/Wredundant-move4.C: New test. Added: trunk/gcc/testsuite/g++.dg/cpp0x/Wredundant-move1.C trunk/gcc/testsuite/g++.dg/cpp0x/Wredundant-move2.C trunk/gcc/testsuite/g++.dg/cpp0x/Wredundant-move3.C trunk/gcc/testsuite/g++.dg/cpp0x/Wredundant-move4.C Modified: trunk/gcc/ChangeLog trunk/gcc/c-family/ChangeLog trunk/gcc/c-family/c.opt trunk/gcc/cp/ChangeLog trunk/gcc/cp/typeck.c trunk/gcc/doc/invoke.texi trunk/gcc/testsuite/ChangeLog
Implemented for GCC 9. This warning should still be extended to handle initializers, where the std::move can also be redundant.