diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-11-29 05:27:40 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-11-29 05:27:40 +0000 |
commit | 675ea99a2a69e82159996035cc3279579531a9a2 (patch) | |
tree | 2faa3feafd8586acda8b159eb77d977d71416249 /clang/lib/Parse/ParseTemplate.cpp | |
parent | ad9e828c89bd51e5bd104aede1e08c05bc4a8491 (diff) | |
download | bcm5719-llvm-675ea99a2a69e82159996035cc3279579531a9a2.tar.gz bcm5719-llvm-675ea99a2a69e82159996035cc3279579531a9a2.zip |
PR10101: Recover better from a common copy-paste error: if a function
declaration at namespace scope is followed by a semicolon and an open-brace
(or in C++, a 'try', ':' or '='), then the error is probably a function
definition with a spurious ';', rather than a mysterious '{'.
llvm-svn: 145372
Diffstat (limited to 'clang/lib/Parse/ParseTemplate.cpp')
-rw-r--r-- | clang/lib/Parse/ParseTemplate.cpp | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/clang/lib/Parse/ParseTemplate.cpp b/clang/lib/Parse/ParseTemplate.cpp index b485f1e9777..91cf8e81c2a 100644 --- a/clang/lib/Parse/ParseTemplate.cpp +++ b/clang/lib/Parse/ParseTemplate.cpp @@ -240,6 +240,20 @@ Parser::ParseSingleDeclarationAfterTemplate( return 0; } + // Check for a stray semicolon in a function definition. + if (DeclaratorInfo.isFunctionDeclarator() && Tok.is(tok::semi) && + Context == Declarator::FileContext) { + const Token &Next = NextToken(); + if (Next.is(tok::l_brace) || Next.is(tok::kw_try) || + Next.is(tok::equal) || Next.is(tok::colon)) { + SourceLocation SemiLoc = ConsumeToken(); + Diag(SemiLoc, diag::err_stray_semi_function_definition) + << FixItHint::CreateRemoval(SemiLoc); + assert(!isDeclarationAfterDeclarator() && + isStartOfFunctionDefinition(DeclaratorInfo)); + } + } + // If we have a declaration or declarator list, handle it. if (isDeclarationAfterDeclarator()) { // Parse this declaration. @@ -264,16 +278,8 @@ Parser::ParseSingleDeclarationAfterTemplate( if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) { Diag(Tok, diag::err_function_declared_typedef); - if (Tok.is(tok::l_brace)) { - // This recovery skips the entire function body. It would be nice - // to simply call ParseFunctionDefinition() below, however Sema - // assumes the declarator represents a function, not a typedef. - ConsumeBrace(); - SkipUntil(tok::r_brace, true); - } else { - SkipUntil(tok::semi); - } - return 0; + // Recover by ignoring the 'typedef'. + DS.ClearStorageClassSpecs(); } return ParseFunctionDefinition(DeclaratorInfo, TemplateInfo); } |