Add -Wempty-statement, which warns about empty statements, i.e. lone ';'
authorChristoph Mallon <christoph.mallon@gmx.de>
Fri, 14 Dec 2007 10:04:41 +0000 (10:04 +0000)
committerChristoph Mallon <christoph.mallon@gmx.de>
Fri, 14 Dec 2007 10:04:41 +0000 (10:04 +0000)
[r18740]

parser.c
warning.c
warning.h

index 621be2d..53707c3 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -5451,6 +5451,9 @@ static statement_t *parse_statement(void)
                break;
 
        case ';':
+               if (warning.empty_statement) {
+                       warningf(HERE, "statement is empty");
+               }
                next_token();
                statement = NULL;
                break;
index 2689007..8f5bfc8 100644 (file)
--- a/warning.c
+++ b/warning.c
@@ -18,6 +18,7 @@ void set_warning_opt(const char *const opt)
 #define SET(y)    warning.y = state;
 #define OPT(x, y) OPTX(x) SET(y)
        OPT("char-subscripts",               char_subscripts)
+       OPT("empty-statement",               empty_statement)
        OPT("error",                         s_are_errors)
        OPT("fatal-errors",                  fatal_errors)
        OPT("format",                        check_format)
@@ -54,6 +55,7 @@ void set_warning_opt(const char *const opt)
 warning_t warning = {
        .char_subscripts               = true,
        .check_format                  = true,
+       .empty_statement               = true,
        .fatal_errors                  = false,
        .implicit_function_declaration = true,
        .implicit_int                  = true,
index 0b145cc..f1eafb7 100644 (file)
--- a/warning.h
+++ b/warning.h
@@ -19,6 +19,9 @@ typedef struct warning_t {
        bool declaration_after_statement:1;   /* Warn when a declaration is found after a statement in a block */
        bool deprecated_declarations:1;       /* Warn about uses of functions, variables and types marked as deprecated by using the 'deprecated' attribute */
        bool div_by_zero:1;                   /* Warn about compile-time integer division by zero */
+#endif
+       bool empty_statement:1;               /* Warn about empty statements, i.e. lone ';'  */
+#if 0 // TODO
        bool endif_labels:1;                  /* Warn whenever an '#else' or an '#endif' are followed by text */
 #endif
        bool fatal_errors:1;                  /* First error stops the compilation */