On 1/7/19 4:29 PM, Marek Polacek wrote:
This patch fixes bogus -Wredundant-move warnings reported in 88692 and 87882.

To quickly recap, this warning is supposed to warn for cases like

struct T { };

T fn(T t)
{
   return std::move (t);
}

where NRVO isn't applicable for T because it's a parameter, but it's
a local variable and we're returning, so C++11 says activate move
semantics, so the std::move is redundant.  But, as these testcases show,
we're failing to realize that that is not the case when returning *this,
which is disguised as an ordinary PARM_DECL, and treat_lvalue_as_rvalue_p
was fooled by that.

Hmm, the function isn't returning 'this', it's returning '*this'. I guess what's happening is that in order to pass *this to the reference parameter of move, we end up converting it from pointer to reference by NOP_EXPR, and the STRIP_NOPS in maybe_warn_pessimizing_move throws that away so that it then thinks we're returning 'this'. I expect the same thing could happen with any parameter of pointer-to-class type.

Jason

Reply via email to