]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - parser.cpp
Fix #171
[xonotic/gmqcc.git] / parser.cpp
index dbf70f4a9a8ff2bbe94525ee2e97940b7db5efeb..995e26e521a14d59f3d83482c0285bc609b19d2e 100644 (file)
@@ -6226,7 +6226,7 @@ bool parser_finish(parser_t *parser, const char *output)
         if (!ast_istype(it, ast_value))
             continue;
         asvalue = (ast_value*)it;
-        if (!asvalue->m_uses && asvalue->m_vtype != TYPE_FUNCTION) {
+        if (!asvalue->m_uses && asvalue->m_cvq != CV_CONST && asvalue->m_vtype != TYPE_FUNCTION) {
             retval = retval && !compile_warning(asvalue->m_context, WARN_UNUSED_VARIABLE,
                                                 "unused global: `%s`", asvalue->m_name);
         }
@@ -6324,11 +6324,15 @@ bool parser_finish(parser_t *parser, const char *output)
     }
     parser_remove_ast(parser);
 
-    if (compile_Werrors) {
-        con_out("*** there were warnings treated as errors\n");
-        compile_show_werrors();
-        retval = false;
-    }
+    auto fnCheckWErrors = [&retval]() {
+        if (compile_Werrors) {
+            con_out("*** there were warnings treated as errors\n");
+            compile_show_werrors();
+            retval = false;
+        }
+    };
+
+    fnCheckWErrors();
 
     if (retval) {
         if (OPTS_OPTION_BOOL(OPTION_DUMPFIN))
@@ -6339,6 +6343,9 @@ bool parser_finish(parser_t *parser, const char *output)
             delete ir;
             return false;
         }
+
+        // ir->generate can generate compiler warnings
+        fnCheckWErrors();
     }
     delete ir;
     return retval;