]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
-Weffectless-statement, on by default, creates 'statement has no effect' warning
authorWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 23 Aug 2012 18:52:09 +0000 (20:52 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 23 Aug 2012 18:52:09 +0000 (20:52 +0200)
main.c
parser.c
warns.def

diff --git a/main.c b/main.c
index acc03c8fb45588388207f5f15414c0dc3b8ad320..36b3349ea26e25d75cae2fe24ac50059f193373e 100644 (file)
--- a/main.c
+++ b/main.c
@@ -402,6 +402,7 @@ int main(int argc, char **argv) {
     options_set(opts_warn, WARN_VARIADIC_FUNCTION, true);
     options_set(opts_warn, WARN_FRAME_MACROS, true);
     options_set(opts_warn, WARN_UNUSED_VARIABLE, true);
+    options_set(opts_warn, WARN_EFFECTLESS_STATEMENT, true);
 
     if (!options_parse(argc, argv)) {
         return usage();
index d382dd1e15365d83d0b6ede568eafc0f57a7bb40..892ef2f3c829c5f8efeb4c0d32efdc623689f437 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1768,6 +1768,13 @@ static bool parser_parse_statement(parser_t *parser, ast_block *block, ast_expre
         if (!exp)
             return false;
         *out = exp;
+        if (!ast_istype(exp, ast_store) &&
+            !ast_istype(exp, ast_call) &&
+            !ast_istype(exp, ast_binstore))
+        {
+            if (parsewarning(parser, WARN_EFFECTLESS_STATEMENT, "statement has no effect"))
+                return false;
+        }
         return true;
     }
 }
index b3abd78c68af34a0c4e12e5e4f031edc32d9a01d..1f47fede223b546b721af320c1b5f76a9b6200ae 100644 (file)
--- a/warns.def
+++ b/warns.def
@@ -16,3 +16,4 @@ GMQCC_DEFINE_FLAG(VOID_VARIABLES)
 GMQCC_DEFINE_FLAG(IMPLICIT_FUNCTION_POINTER)
 GMQCC_DEFINE_FLAG(VARIADIC_FUNCTION)
 GMQCC_DEFINE_FLAG(FRAME_MACROS)
+GMQCC_DEFINE_FLAG(EFFECTLESS_STATEMENT)