From: Josh Triplett <josh@joshtriplett.org>
To: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Cc: Christopher Li <sparse@chrisli.org>,
Sparse Mailing-list <linux-sparse@vger.kernel.org>
Subject: Re: [PATCH 2/5] Fix some "enum value 'SYM_...' not handled in switch" warnings
Date: Wed, 22 Jul 2009 21:42:42 -0700 [thread overview]
Message-ID: <20090723044241.GA6472@feather> (raw)
In-Reply-To: <4A663005.5090009@ramsay1.demon.co.uk>
On Tue, Jul 21, 2009 at 10:15:49PM +0100, Ramsay Jones wrote:
> Josh Triplett wrote:
> > On Sat, Jul 18, 2009 at 09:41:46PM +0100, Ramsay Jones wrote:
> >> These warnings were issued by gcc v3.4.4, but not by gcc v4.1.2.
> >> So I guess gcc probably found these warnings to be too noisy ...
> > [...]
> >> --- a/parse.c
> >> +++ b/parse.c
> >> @@ -2616,6 +2616,8 @@ struct token *external_declaration(struct token *token, struct symbol_list **lis
> >> case SYM_ENUM:
> >> case SYM_RESTRICT:
> >> base_type->ident = ident;
> >> + default:
> >> + break;
> >> }
> >
> > I don't think you want to add defaults like this just to avoid warnings.
> > Warnings like that can help when adding a new item to an enum, to find
> > the places where you need to extend the code to hand the new item. And
> > since current GCC doesn't even issue the warning by default, it seems
> > even more unnecessary to add that default case.
> >
>
> OK...
>
> So, if I understand your argument, in order to make the best use of these
> warnings, then the correct change would look like the diff given below,
> and (for more up-to-date gcc) add -Wswitch-enum to CFLAGS (at least
> occasionally).
[...]
> diff --git a/parse.c b/parse.c
> index e5ad867..afe39c3 100644
> --- a/parse.c
> +++ b/parse.c
> @@ -2616,6 +2616,23 @@ struct token *external_declaration(struct token *token, struct symbol_list **lis
> case SYM_ENUM:
> case SYM_RESTRICT:
> base_type->ident = ident;
> + break;
> + case SYM_UNINITIALIZED:
> + case SYM_PREPROCESSOR:
> + case SYM_BASETYPE:
> + case SYM_NODE:
> + case SYM_PTR:
> + case SYM_FN:
> + case SYM_ARRAY:
> + case SYM_TYPEDEF:
> + case SYM_TYPEOF:
> + case SYM_MEMBER:
> + case SYM_BITFIELD:
> + case SYM_LABEL:
> + case SYM_FOULED:
> + case SYM_KEYWORD:
> + case SYM_BAD:
> + break;
This represents exactly why more recent GCC defaults this warning to
off. ;)
No, I don't think writing the code this way helps. I think it makes
more sense to leave the warning off and not bother placating older
versions of GCC.
- Josh Triplett
prev parent reply other threads:[~2009-07-23 4:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-18 20:41 [PATCH 2/5] Fix some "enum value 'SYM_...' not handled in switch" warnings Ramsay Jones
2009-07-19 14:01 ` Josh Triplett
2009-07-21 21:15 ` Ramsay Jones
2009-07-22 0:29 ` Christopher Li
2009-07-24 18:25 ` Ramsay Jones
2009-07-24 20:13 ` Christopher Li
2009-07-23 4:42 ` Josh Triplett [this message]
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=20090723044241.GA6472@feather \
--to=josh@joshtriplett.org \
--cc=linux-sparse@vger.kernel.org \
--cc=ramsay@ramsay1.demon.co.uk \
--cc=sparse@chrisli.org \
/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 NNTP newsgroup(s).