]> granicus.if.org Git - clang/commitdiff
Fix PR3172: if we see an eof or } at the top level, reject it.
authorChris Lattner <sabre@nondot.org>
Mon, 8 Dec 2008 21:59:01 +0000 (21:59 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 8 Dec 2008 21:59:01 +0000 (21:59 +0000)
This is important because ParseDeclarationOrFunctionDefinition
skips to, but does not consume, an } on error.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60719 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/Parser.cpp
test/Parser/recovery-3.c

index bce73ccdeb4d7d4a33d27cc7aae9244838011b33..8a5498828e3bd4032d2919250fe496b0742b50e1 100644 (file)
@@ -295,6 +295,7 @@ void Parser::ParseTranslationUnit() {
 }
 
 /// ParseExternalDeclaration:
+///
 ///       external-declaration: [C99 6.9], declaration: [C++ dcl.dcl]
 ///         function-definition
 ///         declaration
@@ -318,6 +319,13 @@ Parser::DeclTy *Parser::ParseExternalDeclaration() {
     ConsumeToken();
     // TODO: Invoke action for top-level semicolon.
     return 0;
+  case tok::r_brace:
+    Diag(Tok, diag::err_expected_external_declaration);
+    ConsumeBrace();
+    return 0;
+  case tok::eof:
+    Diag(Tok, diag::err_expected_external_declaration);
+    return 0;
   case tok::kw___extension__: {
     // __extension__ silences extension warnings in the subexpression.
     ExtensionRAIIObject O(Diags);  // Use RAII to do this.
@@ -352,6 +360,7 @@ Parser::DeclTy *Parser::ParseExternalDeclaration() {
   case tok::kw_export:    // As in 'export template'
     // A function definition cannot start with a these keywords.
     return ParseDeclaration(Declarator::FileContext);
+       
   default:
     // We can't tell whether this is a function-definition or declaration yet.
     return ParseDeclarationOrFunctionDefinition();
index 40cf8cd709ddab78d48a5819b3b9627e508b9662..955d7288277e87aefd4856930dca630d4c3cee94 100644 (file)
@@ -7,3 +7,8 @@ static char *f (char * (*g) (char **, int), char **p, ...) {
     s = g (p, __builtin_va_arg(v, int));    // expected-error {{identifier}} expected-warning {{extension}}
 }
 
+
+// PR3172
+} // expected-error {{expected external declaration}}
+
+