Fix PR3031 by silencing follow-on errors in invalid declarations.

llvm-svn: 59027
This commit is contained in:
Chris Lattner 2008-11-11 06:13:16 +00:00
parent 2126a6d3c4
commit 8c5dd730ce
5 changed files with 11 additions and 6 deletions

View File

@ -1494,6 +1494,7 @@ void Parser::ParseDirectDeclarator(Declarator &D) {
else else
Diag(Tok, diag::err_expected_ident_lparen); // Expected identifier or '('. Diag(Tok, diag::err_expected_ident_lparen); // Expected identifier or '('.
D.SetIdentifier(0, Tok.getLocation()); D.SetIdentifier(0, Tok.getLocation());
D.setInvalidType(true);
} }
assert(D.isPastIdentifier() && assert(D.isPastIdentifier() &&

View File

@ -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 // All of these full declarators require an identifier. If it doesn't have
// one, the ParsedFreeStandingDeclSpec action should be used. // one, the ParsedFreeStandingDeclSpec action should be used.
if (II == 0) { if (II == 0) {
Diag(D.getDeclSpec().getSourceRange().getBegin(), if (!D.getInvalidType()) // Reject this if we think it is valid.
diag::err_declarator_need_ident, Diag(D.getDeclSpec().getSourceRange().getBegin(),
D.getDeclSpec().getSourceRange(), D.getSourceRange()); diag::err_declarator_need_ident,
D.getDeclSpec().getSourceRange(), D.getSourceRange());
return 0; return 0;
} }

View File

@ -32,3 +32,7 @@ int test3(x,
int test4(x, x) int x; {} /* expected-error {{redefinition of parameter 'x'}} */ int test4(x, x) int x; {} /* expected-error {{redefinition of parameter 'x'}} */
// PR3031
int (test5), ; // expected-error {{expected identifier or '('}}

View File

@ -16,7 +16,7 @@ int *h = &x;
int test() { int test() {
int a[10]; int a[10];
int b[10] = a; // expected-error {{initialization with "{...}" expected}} 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}}
} }

View File

@ -1,8 +1,7 @@
// RUN: clang %s -fsyntax-only -verify // RUN: clang %s -fsyntax-only -verify
void test() { void test() {
char = 4; // expected-error {{expected identifier}} expected-error{{declarator requires an identifier}} char = 4; // expected-error {{expected identifier}}
} }