linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tony Camuso <tcamuso@redhat.com>
To: Christopher Li <sparse@chrisli.org>
Cc: Linux-Sparse <linux-sparse@vger.kernel.org>, nicstange@gmail.com
Subject: Re: [PATCH 2/3 v2] Handle all enum members in case statements
Date: Tue, 4 Aug 2015 19:52:14 -0400	[thread overview]
Message-ID: <55C1502E.5050609@redhat.com> (raw)
In-Reply-To: <CANeU7Qk7Xvs6RQuzDxq-9BrqCg-6VXnDUxmgwkREpWVX4Y2ynQ@mail.gmail.com>


On 08/04/2015 07:31 PM, Christopher Li wrote:
> On Tue, Aug 4, 2015 at 8:06 AM, Tony Camuso <tcamuso@redhat.com> wrote:
>> Missing enum members in case statements in c2xml.c and parse.c were
>> causing compile time complaints by gcc 5.1.1. Better to explicitly
>> handle all enum members of the switch variable in case statements,
>> even if they just break.
>>                  break;
>> +       case SYM_PREPROCESSOR:
>> +       case SYM_BASETYPE:
>> +       case SYM_NODE:
>> +       case SYM_PTR:
>> +       case SYM_ARRAY:
>> +       case SYM_ENUM:
>> +       case SYM_TYPEDEF:
>> +       case SYM_TYPEOF:
>> +       case SYM_MEMBER:
>> +       case SYM_BITFIELD:
>> +       case SYM_LABEL:
>> +       case SYM_RESTRICT:
>> +       case SYM_FOULED:
>> +       case SYM_KEYWORD:
>> +       case SYM_BAD:
>> +               break;
>
> I think adding a "default: break" should work. I like your previous patch
> better, except maybe adding a line break after default.
>

It was mentioned to me that the new prevailing wisdom is to "Prefer
compile time errors to runtime errors", such that each enum'd value
of a switch variable should be explicitly handled.

I seem to have violated the spirit of that paradigm by using fall through.

I could add a new line and "break" statement after each case.

Or, if you prefer, I can resubmit the original patch with a linefeed after
the "default:" for good form. Either way, I believe the compiler optimize
them the same.

>
>>                          case SYM_ENUM:
>>                          case SYM_RESTRICT:
>>                                  base_type->ident = ident;
>> +                       case SYM_PREPROCESSOR:
>> +                       case SYM_BASETYPE:
>
> I notice this has the follow through behavior. It is not a bug.
> But if some one append some new case there, it is easy to
> cause unintended follow through. It is better add a break there.

It may not be a bug today, but without an explicit break for each,
it's a potential bug.

The whole reason for explicitly listing the existing enum members is so
that new cases for which "break" may not be the correct solution can be
easily identified at compile time.

Tony



  reply	other threads:[~2015-08-04 23:52 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-30  0:26 [PATCH 0/3] Minor enhancements and fixes Tony Camuso
2015-07-30  0:26 ` [PATCH 1/3] .gitignore: add cscope and Qt project files Tony Camuso
2015-08-03 17:41   ` [PATCH 1/3 v2] " Tony Camuso
2015-08-08  3:58     ` Christopher Li
2015-08-10 11:18       ` Tony Camuso
2015-08-10 12:33   ` [PATCH 1/3 v3] " Tony Camuso
2015-07-30  0:26 ` [PATCH 2/3] c2xml.c, parse.c: gcc 5+ stricter case statement parsing Tony Camuso
2015-08-04 12:06   ` [PATCH 2/3 v2] Handle all enum members in case statements Tony Camuso
2015-08-04 23:31     ` Christopher Li
2015-08-04 23:52       ` Tony Camuso [this message]
     [not found]         ` <CANeU7Q=QAtRqDP36k8uOd9_XgzqjJ0du5SO2WpMEcjp8+mg3CQ@mail.gmail.com>
2015-08-10 11:16           ` Tony Camuso
2015-08-10 12:35   ` [PATCH 2/3 v3] Add default case to switches on enum variables Tony Camuso
2015-07-30  0:26 ` [PATCH 3/3] Add NOWARN and NOERR compile conditions Tony Camuso
2015-07-30  2:55   ` Josh Triplett
2015-07-30 11:45     ` Tony Camuso
2015-07-31 23:46       ` Christopher Li
2015-08-01 11:09         ` Tony Camuso
2015-08-01 17:52           ` Josh Triplett
2015-08-01 18:45           ` Christopher Li
2015-08-02 13:42             ` Tony Camuso
2015-08-02 23:16             ` Tony Camuso
2015-08-02 23:22             ` Tony Camuso
2015-08-03 11:23               ` Nicolai Stange
2015-08-03 11:47                 ` Tony Camuso
2015-07-31 17:07     ` Tony Camuso
2015-07-31 17:12   ` [PATCH 3/3 V2] lib.c: add Wall_off switch Tony Camuso
2015-07-31 18:01     ` Tony Camuso
2015-07-31 19:27   ` [PATCH 3/3 V3] Add Wall_off switch to disable errors and warnings Tony Camuso
2015-08-01 12:59     ` Sam Ravnborg
2015-08-01 13:52       ` Tony Camuso
2015-08-03 16:35   ` [PATCH 3/3 v4] " Tony Camuso
2016-01-05  1:19     ` Luc Van Oostenryck
2016-01-13 14:39       ` Tony Camuso
2015-08-03 18:10 ` [PATCH 0/3] Minor enhancements and fixes Tony Camuso
2015-12-02 18:52 ` Tony Camuso
2016-02-02 18:54   ` Christopher Li

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=55C1502E.5050609@redhat.com \
    --to=tcamuso@redhat.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=nicstange@gmail.com \
    --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).