diff options
| author | Chris Lattner <sabre@nondot.org> | 2010-02-02 00:37:27 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2010-02-02 00:37:27 +0000 |
| commit | 245c5335b538bfdea9190ae168a8984422cff207 (patch) | |
| tree | a100b3d1c026e233e8c297d37c3cf4d0da3573f2 | |
| parent | 0059c491c1c4b83fd0c17831bffa56a946364801 (diff) | |
| download | bcm5719-llvm-245c5335b538bfdea9190ae168a8984422cff207.tar.gz bcm5719-llvm-245c5335b538bfdea9190ae168a8984422cff207.zip | |
improve diagnostics on missing ; in a struct. Before:
t.c:4:3: error: expected ';' at end of declaration list
int y;
^
t.c:4:8: warning: extra ';' inside a struct or union
int y;
^
t.c:6:1: warning: expected ';' at end of declaration list
};
^
After:
t.c:3:8: error: expected ';' at end of declaration list
int x // expected-error {{expected ';' at end of declaration list}}
^
;
t.c:5:8: warning: expected ';' at end of declaration list
int z
^
;
llvm-svn: 95038
| -rw-r--r-- | clang/lib/Parse/ParseDecl.cpp | 12 | ||||
| -rw-r--r-- | clang/test/Parser/declarators.c | 7 |
2 files changed, 14 insertions, 5 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 8cf7a63397f..5a5f5092db7 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -1750,14 +1750,14 @@ void Parser::ParseStructUnionBody(SourceLocation RecordLoc, ConsumeToken(); if (!Tok.isObjCAtKeyword(tok::objc_defs)) { Diag(Tok, diag::err_unexpected_at); - SkipUntil(tok::semi, true, true); + SkipUntil(tok::semi, true); continue; } ConsumeToken(); ExpectAndConsume(tok::l_paren, diag::err_expected_lparen); if (!Tok.is(tok::identifier)) { Diag(Tok, diag::err_expected_ident); - SkipUntil(tok::semi, true, true); + SkipUntil(tok::semi, true); continue; } llvm::SmallVector<DeclPtrTy, 16> Fields; @@ -1771,12 +1771,14 @@ void Parser::ParseStructUnionBody(SourceLocation RecordLoc, if (Tok.is(tok::semi)) { ConsumeToken(); } else if (Tok.is(tok::r_brace)) { - Diag(Tok, diag::ext_expected_semi_decl_list); + ExpectAndConsume(tok::semi, diag::ext_expected_semi_decl_list); break; } else { - Diag(Tok, diag::err_expected_semi_decl_list); - // Skip to end of block or statement + ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list); + // Skip to end of block or statement to avoid ext-warning on extra ';'. SkipUntil(tok::r_brace, true, true); + // If we stopped at a ';', eat it. + if (Tok.is(tok::semi)) ConsumeToken(); } } diff --git a/clang/test/Parser/declarators.c b/clang/test/Parser/declarators.c index 3831199c8d7..074e2ad7cb8 100644 --- a/clang/test/Parser/declarators.c +++ b/clang/test/Parser/declarators.c @@ -64,3 +64,10 @@ static f; // expected-warning {{type specifier missing, defaults to 'int'}} static g = 4; // expected-warning {{type specifier missing, defaults to 'int'}} static h // expected-warning {{type specifier missing, defaults to 'int'}} __asm__("foo"); + + +struct test9 { + int x // expected-error {{expected ';' at end of declaration list}} + int y; + int z // expected-warning {{expected ';' at end of declaration list}} +}; |

