Only warn about unreachable declaration statements, if at least one declarator has...
authorChristoph Mallon <christoph.mallon@gmx.de>
Thu, 20 Nov 2008 10:56:55 +0000 (10:56 +0000)
committerChristoph Mallon <christoph.mallon@gmx.de>
Thu, 20 Nov 2008 10:56:55 +0000 (10:56 +0000)
[r23844]

parser.c

index ac95ff2..9030b63 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -6120,9 +6120,26 @@ static void check_unreachable(statement_t* const stmt, void *const env)
                case STATEMENT_COMPOUND:
                        if (stmt->compound.statements != NULL)
                                return;
                case STATEMENT_COMPOUND:
                        if (stmt->compound.statements != NULL)
                                return;
-                       /* FALLTHROUGH*/
+                       goto warn_unreachable;
+
+               case STATEMENT_DECLARATION: {
+                       /* Only warn if there is at least one declarator with an initializer.
+                        * This typically occurs in switch statements. */
+                       declaration_statement_t const *const decl = &stmt->declaration;
+                       entity_t                const *      ent  = decl->declarations_begin;
+                       entity_t                const *const last = decl->declarations_end;
+                       for (;; ent = ent->base.next) {
+                               if (ent->kind                 == ENTITY_VARIABLE &&
+                                               ent->variable.initializer != NULL) {
+                                       goto warn_unreachable;
+                               }
+                               if (ent == last)
+                                       return;
+                       }
+               }
 
                default:
 
                default:
+warn_unreachable:
                        if (!stmt->base.reachable)
                                warningf(&stmt->base.source_position, "statement is unreachable");
                        return;
                        if (!stmt->base.reachable)
                                warningf(&stmt->base.source_position, "statement is unreachable");
                        return;