diff options
author | bonzini <bonzini@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-11-14 13:10:41 +0000 |
---|---|---|
committer | bonzini <bonzini@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-11-14 13:10:41 +0000 |
commit | 21e609c59695b33c96a3be63c06933e9a10dd9df (patch) | |
tree | 4e246b3e80d5dc1a3504b96a42dad8946d9320d6 /gcc/c-parser.c | |
parent | 74f602fcb3235c2c848296287a343e56aa57f431 (diff) | |
download | gcc-21e609c59695b33c96a3be63c06933e9a10dd9df.tar.gz |
2010-11-13 Paolo Bonzini <bonzini@gnu.org>
PR c/46462
* c-decl.c (declspecs_add_type): Make variables with error types
integers.
* c-parser.c (c_parser_next_tokens_start_declaration): Two IDs
do not start a declaration before an Objective-C foreach.
(c_parser_declaration_or_fndef): Improve recovery after unknown
type name.
(c_parser_for_statement): Hoist entrance of "foreach context"
before ifs, add corresponding reset where it was missing. Do
not set objc_could_be_foreach_context for C.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@166732 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-parser.c')
-rw-r--r-- | gcc/c-parser.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/gcc/c-parser.c b/gcc/c-parser.c index e5ec2d9b388..577528d8b44 100644 --- a/gcc/c-parser.c +++ b/gcc/c-parser.c @@ -641,7 +641,10 @@ c_parser_next_tokens_start_declaration (c_parser *parser) && token->id_kind == C_ID_ID && (c_parser_peek_2nd_token (parser)->type == CPP_NAME || c_parser_peek_2nd_token (parser)->type == CPP_MULT) - && !lookup_name (token->value)) + && !lookup_name (token->value) + + /* Do not try too hard when we could have "object in array". */ + && !parser->objc_could_be_foreach_context) return true; return false; @@ -1373,10 +1376,12 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, c_parser_peek_token (parser)->value); /* Parse declspecs normally to get a correct pointer type, but avoid - a further "fails to be a type name" error. */ + a further "fails to be a type name" error. Refuse nested functions + since it is not how the user likely wants us to recover. */ c_parser_peek_token (parser)->type = CPP_KEYWORD; c_parser_peek_token (parser)->keyword = RID_VOID; c_parser_peek_token (parser)->value = error_mark_node; + fndef_ok = !nested; } c_parser_declspecs (parser, specs, true, true, start_attr_ok); @@ -4653,14 +4658,15 @@ c_parser_for_statement (c_parser *parser) { /* Parse the initialization declaration or expression. */ object_expression = error_mark_node; + parser->objc_could_be_foreach_context = c_dialect_objc (); if (c_parser_next_token_is (parser, CPP_SEMICOLON)) { + parser->objc_could_be_foreach_context = false; c_parser_consume_token (parser); c_finish_expr_stmt (loc, NULL_TREE); } else if (c_parser_next_tokens_start_declaration (parser)) { - parser->objc_could_be_foreach_context = true; c_parser_declaration_or_fndef (parser, true, true, true, true, true, &object_expression); parser->objc_could_be_foreach_context = false; @@ -4690,7 +4696,6 @@ c_parser_for_statement (c_parser *parser) int ext; ext = disable_extension_diagnostics (); c_parser_consume_token (parser); - parser->objc_could_be_foreach_context = true; c_parser_declaration_or_fndef (parser, true, true, true, true, true, &object_expression); parser->objc_could_be_foreach_context = false; @@ -4714,7 +4719,6 @@ c_parser_for_statement (c_parser *parser) init_expr: { tree init_expression; - parser->objc_could_be_foreach_context = true; init_expression = c_parser_expression (parser).value; parser->objc_could_be_foreach_context = false; if (c_parser_next_token_is_keyword (parser, RID_IN)) @@ -4735,6 +4739,7 @@ c_parser_for_statement (c_parser *parser) } /* Parse the loop condition. In the case of a foreach statement, there is no loop condition. */ + gcc_assert (!parser->objc_could_be_foreach_context); if (!is_foreach_statement) { if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |