[PATCH] Warn on empty switch statements
Aaron Ballman
aaron at aaronballman.com
Wed May 29 12:58:54 PDT 2013
I don't have further justification beyond what Daniel pointed out in
the original PR. Comments as of last June seem to imply we could have
this warning off by default, but that's generally frowned upon. So if
we don't actually want the warning, should I close PR4546 as WONTFIX?
~Aaron
On Wed, May 29, 2013 at 3:49 PM, Richard Smith <richard at metafoo.co.uk> wrote:
> On Wed, May 29, 2013 at 7:35 AM, Aaron Ballman <aaron at aaronballman.com>
> wrote:
>>
>> -Wunreachable-code doesn't warn on empty statement bodies for the
>> switch. So, for instance:
>>
>> int main() {
>> int i = 0;
>> switch(i) {}
>> }
>>
>> yields no warnings in clang with -Wunreachable-code (or -Wall), but at
>> /W3 in MSVC you get: warning C4060: switch statement contains no
>> 'case' or 'default' labels. Will it catch lots of bugs? Probably
>> not. But it also should have basically no false positives either. It
>> would be nice for people who want their code to also be warning-free
>> under MSVC.
>
>
> I think we need more justification for adding the warning than this.
>
> It doesn't seem reasonable to expect us to implement the union of all
> warnings which every existent compiler produces. Some of those warnings are
> really dumb. For instance, /W3 also enables C4800, which I don't think we
> will ever want to implement.
>
> We already warn on:
>
> switch(i);
>
> ... and changing the ';' to '{}' is one of the ways we expect people to
> silence that warning, if (for whatever obscure reason) they really wanted a
> switch with no body.
>
>> On Tue, May 28, 2013 at 11:07 PM, Richard Smith <richard at metafoo.co.uk>
>> wrote:
>> > What kinds of bugs does this catch that -Wunreachable-code misses?
>> >
>> > On Tue, May 28, 2013 at 8:27 AM, Aaron Ballman <aaron at aaronballman.com>
>> > wrote:
>> >>
>> >> This patch addresses PR4546; it warns when a switch statement contains
>> >> a body, but the body does not contain any case or default labels.
>> >>
>> >> ~Aaron
>> >>
>> >> _______________________________________________
>> >> cfe-commits mailing list
>> >> cfe-commits at cs.uiuc.edu
>> >> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>> >>
>> >
More information about the cfe-commits
mailing list