Add an option to control the enum switch warning.

This commit is contained in:
Bill Currie 2013-06-26 09:08:51 +09:00
parent 29df4ac7ee
commit fd1ea9e00e
4 changed files with 16 additions and 1 deletions

View file

@ -314,6 +314,13 @@ Emit a warning when potentially ambiguous logic is used without parentheses.
.B redeclared
Emit a warning when a local variable is redeclared.
.TP
.B switch
Emit a warning when an enum value is not handled in a switch statement that
tests an enum.
Using a default label will cause all otherwise unhandled enum values to be
handled (for good or evil).
.TP
.TP
.B traditional
Emit a warning when code that should be an error is allowed by traditional
\fBqcc\fP.

View file

@ -61,6 +61,7 @@ typedef struct {
qboolean initializer; // Warn on excessive initializer elements
qboolean unimplemented; // Warn on unimplemented class methods
qboolean redeclared; // Warn on redeclared local variables
qboolean enum_switch; // Warn on unhandled enum values in switch
} warn_options_t;
typedef struct {

View file

@ -232,6 +232,8 @@ warning_usage (void)
" interface.\n"
" none Turn off all warnings.\n"
" [no-]precedence Warn about potentially ambiguous logic.\n"
" [no-]switch Warn about unhandled enum values in switch\n"
" statements.\n"
" [no-]redeclared Warn about redeclared local variables.\n"
" [no-]traditional Warn about bad code that qcc allowed.\n"
" [no-]undef-function Warn about calling a yet to be defined\n"
@ -295,6 +297,7 @@ DecodeArgs (int argc, char **argv)
options.warnings.initializer = true;
options.warnings.unimplemented = true;
options.warnings.redeclared = true;
options.warnings.enum_switch = true;
options.single_cpp = true;
options.save_temps = false;
@ -503,6 +506,7 @@ DecodeArgs (int argc, char **argv)
options.warnings.initializer = true;
options.warnings.unimplemented = true;
options.warnings.redeclared = true;
options.warnings.enum_switch = true;
} else if (!(strcasecmp (temp, "none"))) {
options.warnings.cow = false;
options.warnings.undefined_function = false;
@ -517,6 +521,7 @@ DecodeArgs (int argc, char **argv)
options.warnings.initializer = false;
options.warnings.unimplemented = false;
options.warnings.redeclared = false;
options.warnings.enum_switch = false;
} else {
qboolean flag = true;
@ -542,6 +547,8 @@ DecodeArgs (int argc, char **argv)
options.warnings.precedence = flag;
} else if (!strcasecmp (temp, "redeclared")) {
options.warnings.redeclared = flag;
} else if (!strcasecmp (temp, "switch")) {
options.warnings.enum_switch = flag;
} else if (!strcasecmp (temp, "traditional")) {
options.warnings.traditional = flag;
} else if (!strcasecmp (temp, "undef-function")) {

View file

@ -415,7 +415,7 @@ switch_expr (switch_block_t *switch_block, expr_t *break_label,
if (!default_label) {
default_label = &_default_label;
default_label->label = break_label;
if (is_enum (type))
if (options.warnings.enum_switch && is_enum (type))
check_enum_switch (switch_block);
}