[PATCH] [clang-tidy] Add check for possibly incomplete switch statements
Benjamin Bannier
bbannier at gmail.com
Tue Aug 5 10:37:29 PDT 2014
Hi Alexander,
> > While clang issues a warns about a possibly incomplete switch statement
> > when switching over an enum variable and failing to cover all enum
> > values (either explicitly or with a default case), no such warning is
> > emitted if a plain integer variable is used as switch variable.
> >
>
> If we consider this diagnostic useful, then we should implement
> -Wswitch-default in Clang (GCC has it, Clang doesn't).
This is intended to catch different problems than -Wswitch-default, and
a default case is even discouraged in some style guides since it masks
unhandled values when using -Wswitch (explicitly in GCC or implicitly in
clang).
The problem this tries to catch is switching on ints w/o an existing
default. If the switch labels are enum values both GCC and clang will
check for full coverage if one uses -Wswitch; however since the switch
condition won't be of that enum type no full coverage can be guaranteed.
The same problem also exists were the switch labels plain ints, but then
even -Wswitch won't help.
It might be a good idea to add a compiler warning proper for that, but I
have even less experience with that than with writing AST matchers for
clang-tidy.
Btw, I am working on comments in http://reviews.llvm.org/D4784.
Cheers,
Benjamin
--
"Good judgment comes from experience. Experience comes from bad judgment."
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140805/2ae88974/attachment.sig>
More information about the cfe-commits
mailing list