]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
new warning: -Wlocal-constants
authorWolfgang (Blub) Bumiller <blub@speed.at>
Tue, 21 Aug 2012 08:18:55 +0000 (10:18 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Tue, 21 Aug 2012 08:18:55 +0000 (10:18 +0200)
main.c
parser.c
warns.def

diff --git a/main.c b/main.c
index bccac37e94abc6706dd907e010cbfce08e8f248f..d8d1c2e9256d3daad45d431fe9e8bf59c5a8410c 100644 (file)
--- a/main.c
+++ b/main.c
@@ -384,6 +384,7 @@ int main(int argc, char **argv) {
     options_set(opts_warn, WARN_TOO_FEW_PARAMETERS, true);
     options_set(opts_warn, WARN_MISSING_RETURN_VALUES, true);
     options_set(opts_warn, WARN_USED_UNINITIALIZED, true);
+    options_set(opts_warn, WARN_LOCAL_CONSTANTS, true);
 
     if (!options_parse(argc, argv)) {
         return usage();
index 9d461597f0aecca2d95cd6e3d91980fb3f74124a..4874f49deae08885c900e29d8019b69253e64322 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -2115,6 +2115,16 @@ nextvar:
             continue;
         }
 
+        if (localblock && opts_standard == COMPILER_QCC) {
+            if (parsewarning(parser, WARN_LOCAL_CONSTANTS,
+                             "initializing expression turns variable `%s` into a constant in this standard",
+                             var->name) )
+            {
+                ast_value_delete(typevar);
+                return false;
+            }
+        }
+
         if (parser->tok != '=') {
             ast_value_delete(typevar);
             parseerror(parser, "expected '=' or ';'");
index bda137029c8538b316ca5c0258b786e7f4bc22eb..92a2f2b7e402b081471351762f6771e21a5eab52 100644 (file)
--- a/warns.def
+++ b/warns.def
@@ -11,3 +11,4 @@ GMQCC_DEFINE_FLAG(FIELD_REDECLARED)
 GMQCC_DEFINE_FLAG(MISSING_RETURN_VALUES)
 GMQCC_DEFINE_FLAG(TOO_FEW_PARAMETERS)
 GMQCC_DEFINE_FLAG(LOCAL_SHADOWS)
+GMQCC_DEFINE_FLAG(LOCAL_CONSTANTS)