https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90428
--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Marek Polacek <mpola...@gcc.gnu.org>: https://gcc.gnu.org/g:6c136d53e89e32fe9d22e41e5df89c08d3470049 commit r13-2097-g6c136d53e89e32fe9d22e41e5df89c08d3470049 Author: Marek Polacek <pola...@redhat.com> Date: Wed Aug 17 13:36:52 2022 -0400 c++: Extend -Wredundant-move for const-qual objects [PR90428] In this PR, Jon suggested extending the -Wredundant-move warning to warn when the user is moving a const object as in: struct T { }; T f(const T& t) { return std::move(t); } where the std::move is redundant, because T does not have a T(const T&&) constructor (which is very unlikely). Even with the std::move, T(T&&) would not be used because it would mean losing the const. Instead, T(const T&) will be called. I had to restructure the function a bit, but it's better now. This patch depends on my other recent patches to maybe_warn_pessimizing_move. PR c++/90428 gcc/cp/ChangeLog: * typeck.cc (can_do_rvo_p): Rename to ... (can_elide_copy_prvalue_p): ... this. (maybe_warn_pessimizing_move): Extend the -Wredundant-move warning to warn about std::move on a const-qualified object. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/Wredundant-move1.C: Adjust dg-warning. * g++.dg/cpp0x/Wredundant-move9.C: Likewise. * g++.dg/cpp0x/Wredundant-move10.C: New test.