From: Christoph Mallon Date: Fri, 14 Dec 2007 09:44:12 +0000 (+0000) Subject: Implement -Wswitch-default. X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=1a094c0fe58c4e848e98353926e17e26c38d72df;p=cparser Implement -Wswitch-default. [r18737] --- diff --git a/parser.c b/parser.c index 65748f1..621be2d 100644 --- a/parser.c +++ b/parser.c @@ -5075,6 +5075,10 @@ static statement_t *parse_switch(void) statement->body = parse_statement(); current_switch = rem; + if (warning.switch_default && find_default_label(statement) == NULL) { + warningf(statement->statement.source_position, "switch has no default case"); + } + return (statement_t*) statement; } diff --git a/warning.c b/warning.c index 7a718cd..963941b 100644 --- a/warning.c +++ b/warning.c @@ -31,6 +31,7 @@ void set_warning_opt(const char *const opt) OPT("missing-prototypes", missing_prototypes) OPT("redundant-decls", redundant_decls) OPT("strict-prototypes", strict_prototypes) + OPT("switch-default", switch_default) #if 0 OPTX("unused") { SET(unused_function) @@ -52,11 +53,14 @@ void set_warning_opt(const char *const opt) warning_t warning = { .char_subscripts = true, .check_format = true, + .fatal_errors = false, .implicit_function_declaration = true, .implicit_int = true, .missing_declarations = true, .missing_prototypes = true, - .strict_prototypes = true, .redundant_decls = true, + .s_are_errors = false, + .strict_prototypes = true, + .switch_default = false, .unused_value = true }; diff --git a/warning.h b/warning.h index ab2acef..327cb6d 100644 --- a/warning.h +++ b/warning.h @@ -59,8 +59,8 @@ typedef struct warning_t { bool strict_aliasing:1; /* Warn about code which might break the strict aliasing rules that the compiler is using for optimization. */ #endif bool strict_prototypes:1; /* warn if a function declaration has an unspecified parameter list */ -#if 0 // TODO bool switch_default:1; /* Warn whenever a 'switch' statement does not have a 'default' case */ +#if 0 // TODO bool switch_enum:1; /* Warn about 'switch' statements with an enum as index type and missing case labels or case labels outside the enum range TODO has an alias -Wswitch? */ bool traditional:1; /* Warn about certain constructs that behave differently in traditional and ISO C */ bool undef:1; /* Warn if an undefined identifier is evaluated in an '#if' directive */