diff options
author | 2006-03-28 15:10:58 -0500 | |
---|---|---|
committer | 2006-03-28 12:54:00 -0800 | |
commit | ca1f2e9ebf33e78c77c79eb695fe88d843b4f978 (patch) | |
tree | 5bb7922cfabe457791997c6211192dc58fb5702a /symbol.h | |
parent | [PATCH] Attribute "sentinel" (diff) | |
download | sparse-ca1f2e9ebf33e78c77c79eb695fe88d843b4f978.tar.gz sparse-ca1f2e9ebf33e78c77c79eb695fe88d843b4f978.tar.bz2 sparse-ca1f2e9ebf33e78c77c79eb695fe88d843b4f978.zip |
[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>
Diffstat (limited to 'symbol.h')
-rw-r--r-- | symbol.h | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -242,6 +242,13 @@ static inline int is_int_type(const struct symbol *type) type->ctype.base_type == &int_type; } +static inline int is_enum_type(const struct symbol *type) +{ + if (type->type == SYM_NODE) + type = type->ctype.base_type; + return (type->type == SYM_ENUM); +} + static inline int get_sym_type(struct symbol *type) { if (type->type == SYM_NODE) |