]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
-Wreserved-names, -fpermissive allows local variables named 'nil' to be created even...
authorWolfgang Bumiller <blub@speed.at>
Fri, 28 Dec 2012 17:22:09 +0000 (18:22 +0100)
committerWolfgang Bumiller <blub@speed.at>
Fri, 28 Dec 2012 17:22:09 +0000 (18:22 +0100)
opts.c
opts.def
parser.c

diff --git a/opts.c b/opts.c
index 334186b8cf9a034764d38c53734026d350631f74..0594b37ce5b69f8c41dbda2c3abc627cc4b023f4 100644 (file)
--- a/opts.c
+++ b/opts.c
@@ -54,6 +54,7 @@ static void opts_setdefault() {
     opts_set(opts.warn,  WARN_UNREACHABLE_CODE,          true);
     opts_set(opts.warn,  WARN_CPP,                       true);
     opts_set(opts.warn,  WARN_UNKNOWN_ATTRIBUTE,         true);
     opts_set(opts.warn,  WARN_UNREACHABLE_CODE,          true);
     opts_set(opts.warn,  WARN_CPP,                       true);
     opts_set(opts.warn,  WARN_UNKNOWN_ATTRIBUTE,         true);
+    opts_set(opts.warn,  WARN_RESERVED_NAMES,            true);
     /* flags */
     opts_set(opts.flags, ADJUST_VECTOR_FIELDS,           true);
     opts_set(opts.flags, FTEPP,                          false);
     /* flags */
     opts_set(opts.flags, ADJUST_VECTOR_FIELDS,           true);
     opts_set(opts.flags, FTEPP,                          false);
index a77ebe51a07d113af0a3f36f50be7035670090db..1dc3d5c6c3b0800753e568aa6e13e93dc6ff4453 100644 (file)
--- a/opts.def
+++ b/opts.def
@@ -47,6 +47,7 @@
     GMQCC_DEFINE_FLAG(BAIL_ON_WERROR)
     GMQCC_DEFINE_FLAG(LOOP_LABELS)
     GMQCC_DEFINE_FLAG(UNTYPED_NIL)
     GMQCC_DEFINE_FLAG(BAIL_ON_WERROR)
     GMQCC_DEFINE_FLAG(LOOP_LABELS)
     GMQCC_DEFINE_FLAG(UNTYPED_NIL)
+    GMQCC_DEFINE_FLAG(PERMISSIVE)
 #endif
 
 /* warning flags */
 #endif
 
 /* warning flags */
@@ -78,6 +79,7 @@
     GMQCC_DEFINE_FLAG(UNREACHABLE_CODE)
     GMQCC_DEFINE_FLAG(CPP)
     GMQCC_DEFINE_FLAG(UNKNOWN_ATTRIBUTE)
     GMQCC_DEFINE_FLAG(UNREACHABLE_CODE)
     GMQCC_DEFINE_FLAG(CPP)
     GMQCC_DEFINE_FLAG(UNKNOWN_ATTRIBUTE)
+    GMQCC_DEFINE_FLAG(RESERVED_NAMES)
 #endif
 
 #ifdef GMQCC_TYPE_OPTIMIZATIONS
 #endif
 
 #ifdef GMQCC_TYPE_OPTIMIZATIONS
index 78dd48db209616010a9d66e15ae8be8194cbabf4..a47c6ad3b978d78a0a91b1b598e913f654a94c5f 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -4283,6 +4283,13 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
          * Also: if there was a prototype, `var` will be deleted and set to `proto` which
          * is then filled with the previous definition and the parameter-names replaced.
          */
          * Also: if there was a prototype, `var` will be deleted and set to `proto` which
          * is then filled with the previous definition and the parameter-names replaced.
          */
+        if (!strcmp(var->name, "nil")) {
+            if (OPTS_FLAG(UNTYPED_NIL)) {
+                if (!localblock || !OPTS_FLAG(PERMISSIVE))
+                    parseerror(parser, "name `nil` not allowed (try -fpermissive)");
+            } else
+                (void)!parsewarning(parser, WARN_RESERVED_NAMES, "variable name `nil` is reserved");
+        }
         if (!localblock) {
             /* Deal with end_sys_ vars */
             was_end = false;
         if (!localblock) {
             /* Deal with end_sys_ vars */
             was_end = false;