From: Jason Merrill <jason@redhat.com>
To: Marek Polacek <polacek@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH v4] c++: -Wdangling-reference with reference wrapper [PR107532]
Date: Fri, 3 Mar 2023 11:25:06 -0500 [thread overview]
Message-ID: <bc0d3d59-a690-6d93-7f30-24ff37315e42@redhat.com> (raw)
In-Reply-To: <ZAET9y0Wn3wyk7VE@redhat.com>
On 3/2/23 16:24, Marek Polacek wrote:
> On Wed, Mar 01, 2023 at 04:53:23PM -0500, Jason Merrill wrote:
>>> @@ -13791,12 +13830,39 @@ std_pair_ref_ref_p (tree t)
>>> const int& y = (f(1), 42); // NULL_TREE
>>> const int& z = f(f(1)); // f(f(1))
>>> - EXPR is the initializer. */
>>> + EXPR is the initializer. If ARG_P is true, we're processing an argument
>>> + to a function; the point is to distinguish between, for example,
>>> +
>>> + Ref::inner (&TARGET_EXPR <D.2839, F::foo (fm)>)
>>> +
>>> + where we shouldn't warn, and
>>> +
>>> + Ref::inner (&TARGET_EXPR <D.2908, F::foo (&TARGET_EXPR <...>)>)
>>> +
>>> + where we should warn (Ref is a reference_like_class_p so we see through
>>> + it. */
>>> static tree
>>> -do_warn_dangling_reference (tree expr)
>>> +do_warn_dangling_reference (tree expr, bool arg_p)
>>> {
>>> STRIP_NOPS (expr);
>>> + if (TREE_CODE (expr) == ADDR_EXPR)
>>> + expr = TREE_OPERAND (expr, 0);
>>
>> I think if we move this here, we also need to check that expr before
>> STRIP_NOPS had REFERENCE_TYPE. OK with that change.
>
> Sorry but I don't think I can do that. There can be CONVERT_EXPRs
> that need to be stripped, whether arg_p or !arg_p. For example, we can get
> (const int *) f ((const int &) &TARGET_EXPR <D.2765, NON_LVALUE_EXPR <10>>)
> for
> const int& r5 = (42, f(10));
I meant that we only want to strip ADDR_EXPR if 'expr' at the start of
the function had REFERENCE_TYPE, corresponding to
> /* Check that this argument initializes a reference, except for
> the argument initializing the object of a member function. */
> if (!DECL_NONSTATIC_MEMBER_FUNCTION_P (fndecl)
> && !TYPE_REF_P (TREE_TYPE (arg)))
> continue;
above the code for stripping an ADDR_EXPR from an argument that your
patch removes.
If the original expr is a pointer rather than a reference, we don't want
to complain about it pointing to a temporary.
Jason
next prev parent reply other threads:[~2023-03-03 16:25 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-18 17:52 [PATCH] " Marek Polacek
2023-01-18 21:07 ` Jason Merrill
2023-01-19 1:13 ` [PATCH v2] " Marek Polacek
2023-01-19 18:02 ` Jason Merrill
2023-01-20 2:03 ` [PATCH v3] " Marek Polacek
2023-01-20 20:19 ` Jason Merrill
2023-01-24 22:49 ` Marek Polacek
2023-02-06 1:25 ` Jason Merrill
2023-02-07 16:46 ` [PATCH v4] " Marek Polacek
2023-03-01 20:34 ` Marek Polacek
2023-03-01 21:53 ` Jason Merrill
2023-03-02 21:24 ` Marek Polacek
2023-03-03 16:25 ` Jason Merrill [this message]
2023-03-03 17:50 ` [PATCH v5] " Marek Polacek
2023-03-04 2:30 ` Jason Merrill
2023-03-06 21:54 ` [PATCH v6] " Marek Polacek
2023-03-07 14:37 ` 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=bc0d3d59-a690-6d93-7f30-24ff37315e42@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=polacek@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).