From 43aa5cc0afaaef21ee33232bcfb44387a01ccae1 Mon Sep 17 00:00:00 2001 From: Christoph Mallon Date: Sat, 23 Aug 2008 10:14:36 +0000 Subject: [PATCH] Behave more sane (i.e. do not spew implicit int warnings), when encountering garbage tokens outside of functions. [r21379] --- parser.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/parser.c b/parser.c index c6dcd45..b4ac5f1 100644 --- a/parser.c +++ b/parser.c @@ -8569,22 +8569,32 @@ end_error:; */ static void parse_translation_unit(void) { - while (token.type != T_EOF) { - switch (token.type) { - case ';': - /* TODO error in strict mode */ - warningf(HERE, "stray ';' outside of function"); - next_token(); - break; + for (;;) switch (token.type) { + DECLARATION_START + case T_IDENTIFIER: + case T___extension__: + parse_external_declaration(); + break; - case T_asm: - parse_global_asm(); - break; + case T_asm: + parse_global_asm(); + break; - default: - parse_external_declaration(); - break; - } + case T_EOF: + return; + + case ';': + /* TODO error in strict mode */ + warningf(HERE, "stray ';' outside of function"); + next_token(); + break; + + default: + errorf(HERE, "stray %K outside of function", &token); + if (token.type == '(' || token.type == '{' || token.type == '[') + eat_until_matching_token(token.type); + next_token(); + break; } } -- 2.20.1