aboutsummaryrefslogtreecommitdiff
path: root/lib/Parse/Parser.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-07-11 22:42:07 +0000
committerChris Lattner <sabre@nondot.org>2010-07-11 22:42:07 +0000
commit004659a56916f2f81ede507c12516c146d6c0df3 (patch)
treeac27fa629639189ebaf1d692618b164f210a8cf6 /lib/Parse/Parser.cpp
parentc82daefa3062721e98947e08193cd81b4e9df915 (diff)
Fix PR7617 by not entering ParseFunctionDefinition when
a function prototype is followed by a declarator if we aren't parsing a K&R style identifier list. Also, avoid skipping randomly after a declaration if a semicolon is missing. Before we'd get: t.c:3:1: error: expected function body after function declarator void bar(); ^ Now we get: t.c:1:11: error: invalid token after top level declarator void foo() ^ ; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108105 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/Parser.cpp')
-rw-r--r--lib/Parse/Parser.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp
index b51dd26e82..def2ca4088 100644
--- a/lib/Parse/Parser.cpp
+++ b/lib/Parse/Parser.cpp
@@ -521,12 +521,17 @@ bool Parser::isDeclarationAfterDeclarator() const {
/// \brief Determine whether the current token, if it occurs after a
/// declarator, indicates the start of a function definition.
-bool Parser::isStartOfFunctionDefinition() {
+bool Parser::isStartOfFunctionDefinition(const ParsingDeclarator &Declarator) {
+ assert(Declarator.getTypeObject(0).Kind == DeclaratorChunk::Function &&
+ "Isn't a function declarator");
if (Tok.is(tok::l_brace)) // int X() {}
return true;
- if (!getLang().CPlusPlus)
- return isDeclarationSpecifier(); // int X(f) int f; {}
+ // Handle K&R C argument lists: int X(f) int f; {}
+ if (!getLang().CPlusPlus &&
+ Declarator.getTypeObject(0).Fun.isKNRPrototype())
+ return isDeclarationSpecifier();
+
return Tok.is(tok::colon) || // X() : Base() {} (used for ctors)
Tok.is(tok::kw_try); // X() try { ... }
}
@@ -649,7 +654,7 @@ Parser::DeclPtrTy Parser::ParseFunctionDefinition(ParsingDeclarator &D,
// If this declaration was formed with a K&R-style identifier list for the
// arguments, parse declarations for all of the args next.
// int foo(a,b) int a; float b; {}
- if (!FTI.hasPrototype && FTI.NumArgs != 0)
+ if (FTI.isKNRPrototype())
ParseKNRParamDeclarations(D);
// We should have either an opening brace or, in a C++ constructor,