diff --git a/tools/qfcc/doc/man/qfcc.1 b/tools/qfcc/doc/man/qfcc.1 index cf5c6372d..2857ffedd 100644 --- a/tools/qfcc/doc/man/qfcc.1 +++ b/tools/qfcc/doc/man/qfcc.1 @@ -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. diff --git a/tools/qfcc/include/options.h b/tools/qfcc/include/options.h index 131aec720..6be963699 100644 --- a/tools/qfcc/include/options.h +++ b/tools/qfcc/include/options.h @@ -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 { diff --git a/tools/qfcc/source/options.c b/tools/qfcc/source/options.c index e9f67ca0c..4209cbbec 100644 --- a/tools/qfcc/source/options.c +++ b/tools/qfcc/source/options.c @@ -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")) { diff --git a/tools/qfcc/source/switch.c b/tools/qfcc/source/switch.c index dee8bac5f..f6b05547c 100644 --- a/tools/qfcc/source/switch.c +++ b/tools/qfcc/source/switch.c @@ -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); }