[cfe-commits] r58989 - in /cfe/trunk: include/clang/Parse/Parser.h lib/Parse/ParseCXXInlineMethods.cpp test/SemaCXX/constructor-initializer.cpp
Douglas Gregor
doug.gregor at gmail.com
Mon Nov 10 08:59:43 PST 2008
Author: dgregor
Date: Mon Nov 10 10:59:40 2008
New Revision: 58989
URL: http://llvm.org/viewvc/llvm-project?rev=58989&view=rev
Log:
Improve parser error recovery after a constructor initializer
Modified:
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
cfe/trunk/test/SemaCXX/constructor-initializer.cpp
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=58989&r1=58988&r2=58989&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Mon Nov 10 10:59:40 2008
@@ -397,7 +397,8 @@
DeclTy *ParseCXXInlineMethodDef(AccessSpecifier AS, Declarator &D);
void ParseLexedMethodDefs();
- bool ConsumeAndStoreUntil(tok::TokenKind T, TokensTy &Toks);
+ bool ConsumeAndStoreUntil(tok::TokenKind T, TokensTy &Toks,
+ tok::TokenKind EarlyAbortIf = tok::unknown);
//===--------------------------------------------------------------------===//
// C99 6.9: External Definitions.
Modified: cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp?rev=58989&r1=58988&r2=58989&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp (original)
+++ cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp Mon Nov 10 10:59:40 2008
@@ -11,6 +11,7 @@
//
//===----------------------------------------------------------------------===//
+#include "clang/Basic/Diagnostic.h"
#include "clang/Parse/Parser.h"
#include "clang/Parse/DeclSpec.h"
#include "clang/Parse/Scope.h"
@@ -36,7 +37,19 @@
// We may have a constructor initializer here.
if (Tok.is(tok::colon)) {
// Consume everything up to (and including) the left brace.
- ConsumeAndStoreUntil(tok::l_brace, Toks);
+ if (!ConsumeAndStoreUntil(tok::l_brace, Toks, tok::semi)) {
+ // We didn't find the left-brace we expected after the
+ // constructor initializer.
+ if (Tok.is(tok::semi)) {
+ // We found a semicolon; complain, consume the semicolon, and
+ // don't try to parse this method later.
+ Diag(Tok.getLocation(), diag::err_expected_lbrace);
+ ConsumeAnyToken();
+ getCurTopClassStack().pop();
+ return FnD;
+ }
+ }
+
} else {
// Begin by storing the '{' token.
Toks.push_back(Tok);
@@ -82,9 +95,12 @@
/// ConsumeAndStoreUntil - Consume and store the token at the passed token
/// container until the token 'T' is reached (which gets consumed/stored too).
+/// If EarlyAbortIf is specified, then we will stop early if we find that
+/// token at the top level.
/// Returns true if token 'T' was found.
/// NOTE: This is a specialized version of Parser::SkipUntil.
-bool Parser::ConsumeAndStoreUntil(tok::TokenKind T, TokensTy &Toks) {
+bool Parser::ConsumeAndStoreUntil(tok::TokenKind T, TokensTy &Toks,
+ tok::TokenKind EarlyAbortIf) {
// We always want this function to consume at least one token if the first
// token isn't T and if not at EOF.
bool isFirstTokenConsumed = true;
@@ -96,6 +112,10 @@
return true;
}
+ // If we found the early-abort token, return.
+ if (Tok.is(EarlyAbortIf))
+ return false;
+
switch (Tok.getKind()) {
case tok::eof:
// Ran out of tokens.
Modified: cfe/trunk/test/SemaCXX/constructor-initializer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constructor-initializer.cpp?rev=58989&r1=58988&r2=58989&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constructor-initializer.cpp (original)
+++ cfe/trunk/test/SemaCXX/constructor-initializer.cpp Mon Nov 10 10:59:40 2008
@@ -41,3 +41,7 @@
{
}
};
+
+class G : A {
+ G() : A(10); // expected-error{{expected '{'}}
+};
More information about the cfe-commits
mailing list