diff --git a/tools/qfcc/doc/man/qfcc.1 b/tools/qfcc/doc/man/qfcc.1 index 995b023a1..130580e7d 100644 --- a/tools/qfcc/doc/man/qfcc.1 +++ b/tools/qfcc/doc/man/qfcc.1 @@ -281,6 +281,9 @@ interface for a class. .B precedence Emit a warning when potentially ambiguous logic is used without parentheses. .TP +.B redeclared +Emit a warning when a local variable is redeclared. +.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 c61f1cf7c..fbc08a02f 100644 --- a/tools/qfcc/include/options.h +++ b/tools/qfcc/include/options.h @@ -58,6 +58,7 @@ typedef struct { qboolean precedence; // Warn on precedence issues qboolean initializer; // Warn on excessive initializer elements qboolean unimplemented; // Warn on unimplemented class methods + qboolean redeclared; // Warn on redeclared local variables } warn_options_t; typedef struct { diff --git a/tools/qfcc/source/options.c b/tools/qfcc/source/options.c index 6f0a7eafd..890ce5f2b 100644 --- a/tools/qfcc/source/options.c +++ b/tools/qfcc/source/options.c @@ -217,6 +217,7 @@ warning_usage (void) " interface.\n" " none Turn off all warnings.\n" " [no-]precedence Warn about potentially ambiguous logic.\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" " function.\n" @@ -276,6 +277,7 @@ DecodeArgs (int argc, char **argv) options.warnings.precedence = true; options.warnings.initializer = true; options.warnings.unimplemented = true; + options.warnings.redeclared = true; options.single_cpp = true; options.save_temps = false; @@ -417,6 +419,7 @@ DecodeArgs (int argc, char **argv) options.warnings.precedence = true; options.warnings.initializer = true; options.warnings.unimplemented = true; + options.warnings.redeclared = true; } else if (!(strcasecmp (temp, "none"))) { options.warnings.cow = false; options.warnings.undefined_function = false; @@ -430,6 +433,7 @@ DecodeArgs (int argc, char **argv) options.warnings.precedence = false; options.warnings.initializer = false; options.warnings.unimplemented = false; + options.warnings.redeclared = false; } else { qboolean flag = true; @@ -453,6 +457,8 @@ DecodeArgs (int argc, char **argv) options.warnings.interface_check = flag; } else if (!strcasecmp (temp, "precedence")) { options.warnings.precedence = flag; + } else if (!strcasecmp (temp, "redeclared")) { + options.warnings.redeclared = flag; } else if (!strcasecmp (temp, "traditional")) { options.warnings.traditional = flag; } else if (!strcasecmp (temp, "undef-function")) { diff --git a/tools/qfcc/source/qc-parse.y b/tools/qfcc/source/qc-parse.y index f64591b7d..2c4264dd5 100644 --- a/tools/qfcc/source/qc-parse.y +++ b/tools/qfcc/source/qc-parse.y @@ -1733,7 +1733,7 @@ create_def (type_t *type, const char *name, scope_t *scope, warning (0, "local %s shadows param %s", name, def->name); } - if (def->scope == scope) { + if (def->scope == scope && options.warnings.redeclared) { expr_t e; warning (0, "local %s redeclared", name); e.file = def->file;