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.