[PATCH] Warn on empty switch statements

Aaron Ballman aaron at aaronballman.com
Wed May 29 07:35:36 PDT 2013


-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.

~Aaron

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