[cfe-dev] [enum comparison] switch vs if
alex boros via cfe-dev
cfe-dev at lists.llvm.org
Thu Apr 27 06:54:08 PDT 2017
Hi all!
I'm interested in developing a clang static checker for enum comparison in
switch and throwing a warning.
I found out that it already exists in if comparison in clang but my
question is:
Is this on purpose that different enum types don't send warning or int and
enum comparison in switches but send in if?
Example:
enum MIXED_ENUMS_e { E1, E2 };enum MIXED_ENUMS_f { F0, F1, F2, F3 };
void mixed_enums(MIXED_ENUMS_e ee){
int x;
switch (ee)
{
case E1: x = 1; break;
case F1: x = 2; break; // TODO warning: ee and F1 have different types. }
switch (x)
{
case E1: ++x; break; // TODO warning: x and E1 have different
types. case F3: --x; break; // TODO warning: x and F3 have
different types. }
if (ee == F0) {} // Already exsisting warning: ee and F0 have
different types.
*if* (ee == x) {}* // Already exsisting warning: ee and x have
different types.
*}
BR Alex.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170427/b1c3b30f/attachment.html>
More information about the cfe-dev
mailing list