http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52987
Bug #: 52987 Summary: bogus expected ; before for undeclared type Classification: Unclassified Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: m...@gcc.gnu.org void foo(void) { x var; } manuel@gcc12:~/test2$ ~/trunk/186353/build/gcc/cc1plus ~/notdeclared.c void foo() /home/manuel/notdeclared.c:2:3: error: ‘x’ was not declared in this scope x var; ^ /home/manuel/notdeclared.c:2:5: error: expected ‘;’ before ‘var’ x var; ^ manuel@gcc12:~/test2$ clang ~/notdeclared.c /home/manuel/notdeclared.c:2:3: error: use of undeclared identifier 'x' x var; ^ 1 error generated. The "expected ";" before "var"" is bogus. The following patch removes it in this case: --- gcc/cp/parser.c (revision 186353) +++ gcc/cp/parser.c (working copy) @@ -5589,13 +5589,19 @@ cp_parser_postfix_expression (cp_parser while (true) { if (idk == CP_ID_KIND_UNQUALIFIED && TREE_CODE (postfix_expression) == IDENTIFIER_NODE && cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_PAREN)) - /* It is not a Koenig lookup function call. */ - postfix_expression - = unqualified_name_lookup_error (postfix_expression); + { + /* It is not a Koenig lookup function call. */ + postfix_expression = + unqualified_name_lookup_error (postfix_expression); + /* It is better to skip the rest and return here, because at + this point we don't know what this statement is. */ + cp_parser_skip_to_end_of_statement (parser); + return error_mark_node; + } /* Peek at the next token. */ token = cp_lexer_peek_token (parser->lexer); switch (token->type) Unfortunately, undeclared names can occur in many places besides statements, so it fails for things like: int foo(x var) { } I couldn't figure out how tell the context where we are called. :-(