From: Marek Polacek <polacek@redhat.com>
To: Jason Merrill <jason@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH v4] c++: Implement -Wself-move warning [PR81159]
Date: Thu, 25 Aug 2022 17:49:02 -0400 [thread overview]
Message-ID: <YwfuTuK4lyZOw0tL@redhat.com> (raw)
In-Reply-To: <ace7f15f-436c-1a1d-c7e5-2777d8cd6d41@redhat.com>
On Thu, Aug 25, 2022 at 09:25:43AM -0400, Jason Merrill wrote:
> 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.
Ok, I've added the REFERENCE_REF stripping. But I've still left the
COMPONENT_REF in. Perhaps we could say "moving a member" to itself for
COMPONENT_REFs. Or just say "moving 'x' of type 'int' to itself" and
avoid all of this. :)
> I don't see where COMPONENT_REF comes in?
For #1 in the test below the COMPONENT_REF was created in finish_id_expression
-> finish_non_static_data_member -> build_class_member_access_expr and passed
down to maybe_warn_self_move from here:
#0 maybe_warn_self_move (loc=2147483652, lhs=<component_ref 0x7fffea380e10>,
rhs=<indirect_ref 0x7fffea38a220>) at /home/mpolacek/src/gcc/gcc/cp/typeck.cc:8908
#1 0x0000000000f3d03e in cp_build_modify_expr (loc=2147483652, lhs=<component_ref 0x7fffea380e10>,
modifycode=NOP_EXPR, rhs=<indirect_ref 0x7fffea38a220>, complain=3)
at /home/mpolacek/src/gcc/gcc/cp/typeck.cc:9161
#2 0x0000000000f3e461 in build_x_modify_expr (loc=2147483652, lhs=<component_ref 0x7fffea380e10>,
modifycode=NOP_EXPR, rhs=<indirect_ref 0x7fffea38a220>, lookups=<tree 0x0>, complain=3)
at /home/mpolacek/src/gcc/gcc/cp/typeck.cc:9446
#3 0x0000000000d92d4e in cp_parser_assignment_expression (parser=0x7fffea236850, pidk=0x0, cast_p=false,
decltype_p=false) at /home/mpolacek/src/gcc/gcc/cp/parser.cc:10461
> > 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
next prev parent reply other threads:[~2022-08-25 21:49 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-09 16:37 [PATCH] " Marek Polacek
2022-08-15 19:54 ` Jason Merrill
2022-08-18 20:19 ` [PATCH v2] " Marek Polacek
2022-08-19 0:33 ` Jason Merrill
2022-08-19 22:34 ` [PATCH v3] " Marek Polacek
2022-08-20 21:31 ` Jason Merrill
2022-08-23 16:39 ` [PATCH v4] " Marek Polacek
2022-08-23 21:27 ` Jason Merrill
2022-08-24 21:30 ` Marek Polacek
2022-08-25 13:25 ` Jason Merrill
2022-08-25 21:49 ` Marek Polacek [this message]
2022-08-26 0:52 ` Jason Merrill
2022-08-26 17:04 ` [PATCH v5] " Marek Polacek
2022-08-26 17:59 ` Jason Merrill
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YwfuTuK4lyZOw0tL@redhat.com \
--to=polacek@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).