public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Martin Sebor <msebor@gmail.com>
Cc: Gcc Patch List <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] restore -Wunused-variable on a typedef'd variable in a function template (PR 79548)
Date: Thu, 23 Feb 2017 01:11:00 -0000	[thread overview]
Message-ID: <CADzB+2nUGZ5N-dNap48GquOTYgMYCLD1j9tUo_Rxh9OWzM2HrA@mail.gmail.com> (raw)
In-Reply-To: <00eb2a46-a8e8-7744-a093-7eaad8c42e36@gmail.com>

On Wed, Feb 22, 2017 at 3:44 PM, Martin Sebor <msebor@gmail.com> wrote:
> On 02/22/2017 11:02 AM, Jason Merrill wrote:
>>
>> On Tue, Feb 21, 2017 at 4:27 PM, Martin Sebor <msebor@gmail.com> wrote:
>>>>
>>>> Ah, I see, your patch changes attribute unused handling for local
>>>> variables from tracking TREE_USED to lookup_attribute.  I'm not
>>>> opposed to this change, but I'd like to understand why the TREE_USED
>>>> handling wasn't working.
>>>
>>>
>>>
>>> In the test case in the bug:
>>>
>>>   template <class T>
>>>   void g ()
>>>   {
>>>     T t;   // warning, ok
>>>
>>>     typedef T U;
>>>     U u;   // no warning, bug
>>>   }
>>>
>>>   template void g<int>();
>>>
>>> both TREE_USED(T) and TREE_USED(t) are zero in initialize_local_var
>>> so the function doesn't set already_used or TREE_USED(t) and we get
>>> a warning as expected.
>>>
>>> But because TREE_USED(U) is set to 1 in maybe_record_typedef_use
>>> (to implement -Wunused-local-typedefs),  initialize_local_var then
>>> sets already_used to 1 and later also TREE_USED(u) to 1, suppressing
>>> the warning.
>>
>> Hmm, I would expect maybe_record_typedef_use to set TREE_USED on the
>> TYPE_DECL, not on the *_TYPE which initialize_local_var checks.
>
> That's what it does:
>
>   void
>   maybe_record_typedef_use (tree t)
>   {
>     if (!is_typedef_decl (t))
>       return;
>
>     TREE_USED (t) = true;
>   }
>
> Here, t is a TYPE_DECL of the typedef U.

Yes.  It is a TYPE_DECL, not a type.

> It has the effect of TREE_USED (TREE_TYPE (decl)) being set in
> initialize_local_var.  The TREE_USED bit on the type (i.e., on
> TREE_TYPE(decl) where decl is the u in the test case above) is
> set when the function template is instantiated, in
> set_underlying_type called from tsubst_decl.

Aha!  That seems like the problem.  Does removing that copy of
TREE_USED from the decl to the type break anything?

Jason

  reply	other threads:[~2017-02-23  0:43 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-18  2:29 Martin Sebor
2017-02-21 18:10 ` Jason Merrill
2017-02-21 19:09   ` Martin Sebor
2017-02-21 20:35     ` Jason Merrill
2017-02-22  7:48       ` Martin Sebor
2017-02-22 18:10         ` Jason Merrill
2017-02-22 23:52           ` Martin Sebor
2017-02-23  1:11             ` Jason Merrill [this message]
2017-02-23 21:06               ` Martin Sebor
2017-02-23 23:48                 ` Jason Merrill
2017-03-20 21:12                   ` Jason Merrill
2017-03-21 18:40                     ` Martin Sebor
2017-03-21 19:28                       ` Jason Merrill
2017-03-21 22:37                         ` Martin Sebor

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=CADzB+2nUGZ5N-dNap48GquOTYgMYCLD1j9tUo_Rxh9OWzM2HrA@mail.gmail.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=msebor@gmail.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).