[PATCH] Warning for mixing enums of different types
This adds a warning when enums of different types are mixed. I found a
handful of problems with this in my own code -- nothing that testing
could have revealed at this point, but if someone has added an extra
flag to an enum, things would have gone "boom!"
typedef enum { A1, A2 } enumA;
typedef enum { B1 = 10, B2 } enumB;
static void Afunc (enumA a) { }
int
main (int argc, char **argv)
{
enumA a = A1;
switch (A1) {
case A1: break;
case A2: break;
case B1: break; // Warn
case B2: break; // Warn
default: break;
}
switch (1) {
case A1: break;
case A2: break;
case B1: break; // Warn
case B2: break; // Warn
default: break;
}
switch (1) {
case A1 ... B2: break; // Warn
default: break;
}
(void)(1 ? a : B1); // Warn
(void)(A1 == B1); // Warn
(void)(A1 << B1); // No warning wanted
a = B1; // Warn
Afunc (B1); // Warn
return 0;
}
Signed-off-by: Morten Welinder <terra@gnome.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>