On 8/24/22 17:30, Marek Polacek wrote:
On Tue, Aug 23, 2022 at 05:27:00PM -0400, Jason Merrill wrote:
On 8/23/22 09:39, Marek Polacek wrote:
+ tree arg = CALL_EXPR_ARG (fn, 0);
+ extract_op (arg);
+ if (TREE_CODE (arg) == ADDR_EXPR)
+ arg = TREE_OPERAND (arg, 0);
+ tree type = TREE_TYPE (lhs);
+ lhs = maybe_undo_parenthesized_ref (lhs);
+ STRIP_ANY_LOCATION_WRAPPER (lhs);
+ const bool print_var_p = (DECL_P (lhs)
+ || REFERENCE_REF_P (lhs)
+ || TREE_CODE (lhs) == COMPONENT_REF);
Why include REFERENCE_REF_P and COMPONENT_REF? Reference refs should be
stripped before this test, member refs aren't variables.
I'm checking REFERENCE_REF_P and COMPONENT_REF to say "moving a variable"
in #1 and #3. The REFERENCE_REF_P check means that we also say "variable"
for #2. Sure, "A variable is introduced by the declaration of a reference
other than a non-static data member", but I'm not sure if users care about
that here?
If I strip REFERENCE_REFs before the check then the result will be the
same.
That's what I was suggesting, yes: Strip the REFERENCE_REF so DECL_P can
see the decl.
I don't see where COMPONENT_REF comes in?
Or I could keep only the DECL_P check, but then we'll say "moving
an expression" for #1 and #2, which seems strange.
struct S {
int x;
int &r;
void foo () {
x = std::move (x); // #1
r = std::move (r); // #2
};
};
void
foo (int &r)
{
r = std::move (r); // #3
}
Marek