diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index e3094ad7c649..70d65f3b4820 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -1494,6 +1494,7 @@ void Parser::ParseDirectDeclarator(Declarator &D) { else Diag(Tok, diag::err_expected_ident_lparen); // Expected identifier or '('. D.SetIdentifier(0, Tok.getLocation()); + D.setInvalidType(true); } assert(D.isPastIdentifier() && diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 6c71d508953d..879a79b633ae 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -753,9 +753,10 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) { // All of these full declarators require an identifier. If it doesn't have // one, the ParsedFreeStandingDeclSpec action should be used. if (II == 0) { - Diag(D.getDeclSpec().getSourceRange().getBegin(), - diag::err_declarator_need_ident, - D.getDeclSpec().getSourceRange(), D.getSourceRange()); + if (!D.getInvalidType()) // Reject this if we think it is valid. + Diag(D.getDeclSpec().getSourceRange().getBegin(), + diag::err_declarator_need_ident, + D.getDeclSpec().getSourceRange(), D.getSourceRange()); return 0; } diff --git a/clang/test/Parser/declarators.c b/clang/test/Parser/declarators.c index 3e0380ea8786..fb7704faf3d6 100644 --- a/clang/test/Parser/declarators.c +++ b/clang/test/Parser/declarators.c @@ -32,3 +32,7 @@ int test3(x, int test4(x, x) int x; {} /* expected-error {{redefinition of parameter 'x'}} */ + +// PR3031 +int (test5), ; // expected-error {{expected identifier or '('}} + diff --git a/clang/test/Sema/init.c b/clang/test/Sema/init.c index c08500834fb4..ff48b8f5286e 100644 --- a/clang/test/Sema/init.c +++ b/clang/test/Sema/init.c @@ -16,7 +16,7 @@ int *h = &x; int test() { int a[10]; int b[10] = a; // expected-error {{initialization with "{...}" expected}} -int +; // expected-error {{expected identifier or '('}} expected-error {{declarator requires an identifier}} expected-error {{parse error}} +int +; // expected-error {{expected identifier or '('}} expected-error {{parse error}} } diff --git a/clang/test/Sema/invalid-decl.c b/clang/test/Sema/invalid-decl.c index ccd3bc83659f..efc199d39b0a 100644 --- a/clang/test/Sema/invalid-decl.c +++ b/clang/test/Sema/invalid-decl.c @@ -1,8 +1,7 @@ // RUN: clang %s -fsyntax-only -verify void test() { - char = 4; // expected-error {{expected identifier}} expected-error{{declarator requires an identifier}} - + char = 4; // expected-error {{expected identifier}} }