From: Marek Polacek <polacek@redhat.com>
To: Jason Merrill <jason@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>,
Joseph Myers <joseph@codesourcery.com>
Subject: Re: [PATCH v2] c, c++: -Wswitch warning on [[maybe_unused]] enumerator [PR105497]
Date: Tue, 10 May 2022 09:54:12 -0400 [thread overview]
Message-ID: <YnpuhKLgKahGZ4+j@redhat.com> (raw)
In-Reply-To: <580b12c2-fa83-d268-373d-64bee758bf85@redhat.com>
On Tue, May 10, 2022 at 08:58:46AM -0400, Jason Merrill wrote:
> On 5/7/22 18:26, Marek Polacek wrote:
> > Corrected version that avoids an uninitialized warning:
> >
> > This PR complains that we emit the "enumeration value not handled in
> > switch" warning even though the enumerator was marked with the
> > [[maybe_unused]] attribute.
> >
> > The first snag was that I couldn't just check TREE_USED, because
> > the enumerator could have been used earlier in the function, which
> > doesn't play well with the c_do_switch_warnings warning. Instead,
> > I had to check the attributes on the CONST_DECL directly, which led
> > to the second, and worse, snag: in C we don't have direct access to
> > the CONST_DECL for the enumerator.
>
> I wonder if you want to change that instead of working around it?
I wouldn't mind looking into that; I've hit this discrepancy numerous
times throughout the years and it'd be good to unify it so that the
c-common code doesn't need to hack around it.
Let's see how far I'll get...
> > + const bool unused_p = (lookup_attribute ("unused", attrs)
> > + || lookup_attribute ("maybe_unused", attrs));
>
> Why is this calculation...
>
> > node = splay_tree_lookup (cases, (splay_tree_key) value);
> > if (node)
> > {
> > @@ -1769,6 +1784,10 @@ c_do_switch_warnings (splay_tree cases, location_t switch_location,
> > /* We've now determined that this enumerated literal isn't
> > handled by the case labels of the switch statement. */
> > + /* Don't warn if the enumerator was marked as unused. */
> > + if (unused_p)
> > + continue;
>
> ...separate from this test?
Ah, that must be a remnant from a previous version of the patch. No reason
for the separation anymore.
Thanks,
Marek
next prev parent reply other threads:[~2022-05-10 13:54 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-07 22:14 [PATCH] " Marek Polacek
2022-05-07 22:26 ` [PATCH v2] " Marek Polacek
2022-05-10 12:58 ` Jason Merrill
2022-05-10 13:54 ` Marek Polacek [this message]
2022-05-17 23:55 ` [PATCH v3] " Marek Polacek
2022-05-18 14:24 ` 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=YnpuhKLgKahGZ4+j@redhat.com \
--to=polacek@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
--cc=joseph@codesourcery.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).