give stray-semicolon warning a name
[cparser] / parser.c
index e8997b4..e0e2503 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -36,7 +36,7 @@
 #include "entity_t.h"
 #include "attribute_t.h"
 #include "lang_features.h"
-#include "walk_statements.h"
+#include "walk.h"
 #include "warning.h"
 #include "printer.h"
 #include "adt/bitfiddle.h"
@@ -1547,7 +1547,6 @@ unary:
                        return;
 
                EXPR_LITERAL_CASES
-               case EXPR_UNKNOWN:
                case EXPR_INVALID:
                case EXPR_STRING_LITERAL:
                case EXPR_WIDE_STRING_LITERAL:
@@ -3650,7 +3649,7 @@ static type_t *construct_declarator_type(construct_type_t *construct_list,
                                errorf(pos, "function returning array is not allowed");
                        } else {
                                if (skipped_return_type->base.qualifiers != 0) {
-                                       warningf(WARN_OTHER, pos, "type qualifiers in return type of function type are meaningless");
+                                       warningf(WARN_IGNORED_QUALIFIERS, pos, "type qualifiers in return type of function type are meaningless");
                                }
                        }
 
@@ -4830,9 +4829,6 @@ static bool expression_returns(expression_t const *const expr)
                        return
                                expression_returns(expr->binary.left) &&
                                expression_returns(expr->binary.right);
-
-               case EXPR_UNKNOWN:
-                       break;
        }
 
        panic("unhandled expression");
@@ -8527,7 +8523,6 @@ static void semantic_binexpr_assign(binary_expression_t *expression)
 static bool expression_has_effect(const expression_t *const expr)
 {
        switch (expr->kind) {
-               case EXPR_UNKNOWN:                    break;
                case EXPR_INVALID:                    return true; /* do NOT warn */
                case EXPR_REFERENCE:                  return false;
                case EXPR_REFERENCE_ENUM_VALUE:       return false;
@@ -8746,7 +8741,6 @@ static expression_t *parse_subexpression(precedence_t precedence)
                left = parser->infix_parser(left);
 
                assert(left != NULL);
-               assert(left->kind != EXPR_UNKNOWN);
        }
 
        return left;
@@ -9279,8 +9273,18 @@ end_error:
        statement->ifs.true_statement = true_stmt;
        rem_anchor_token(T_else);
 
+       if (true_stmt->kind == STATEMENT_EMPTY) {
+               warningf(WARN_EMPTY_BODY, HERE,
+                       "suggest braces around empty body in an ‘if’ statement");
+       }
+
        if (next_if(T_else)) {
                statement->ifs.false_statement = parse_inner_statement();
+
+               if (statement->ifs.false_statement->kind == STATEMENT_EMPTY) {
+                       warningf(WARN_EMPTY_BODY, HERE,
+                                       "suggest braces around empty body in an ‘if’ statement");
+               }
        } else if (true_stmt->kind == STATEMENT_IF &&
                        true_stmt->ifs.false_statement != NULL) {
                source_position_t const *const pos = &true_stmt->base.source_position;
@@ -10416,7 +10420,7 @@ static void parse_external(void)
 
                case ';':
                        if (!strict_mode) {
-                               warningf(WARN_OTHER, HERE, "stray ';' outside of function");
+                               warningf(WARN_STRAY_SEMICOLON, HERE, "stray ';' outside of function");
                                next_token();
                                return;
                        }