]> granicus.if.org Git - clang/commitdiff
Diagnose a missing ')' on what looks like a statement expression.
authorJohn McCall <rjmccall@apple.com>
Wed, 6 Apr 2011 02:35:25 +0000 (02:35 +0000)
committerJohn McCall <rjmccall@apple.com>
Wed, 6 Apr 2011 02:35:25 +0000 (02:35 +0000)
A situation where we can get an invalid ExprResult without an error.
Fixes PR8394.  Patch by Justin Bogner!

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

lib/Parse/ParseExpr.cpp
test/Parser/expressions.c

index 510e2c2801a085a193c3c80793d34bfc6304e5a0..d8d73e92393583b85f782cee1b6e426ccadd62d2 100644 (file)
@@ -1631,6 +1631,9 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
     ConsumeCodeCompletionToken();
     return ExprError();
   }
+
+  // None of these cases should fall through with an invalid Result
+  // unless they've already reported an error.
   
   if (ExprType >= CompoundStmt && Tok.is(tok::l_brace)) {
     Diag(Tok, diag::ext_gnu_statement_expr);
@@ -1639,7 +1642,7 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
     ExprType = CompoundStmt;
 
     // If the substmt parsed correctly, build the AST node.
-    if (!Stmt.isInvalid() && Tok.is(tok::r_paren))
+    if (!Stmt.isInvalid())
       Result = Actions.ActOnStmtExpr(OpenLoc, Stmt.take(), Tok.getLocation());
 
   } else if (ExprType >= CompoundLiteral &&
@@ -1737,6 +1740,8 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
     
     Result = ParseExpression();
     ExprType = SimpleExpr;
+
+    // Don't build a paren expression unless we actually match a ')'.
     if (!Result.isInvalid() && Tok.is(tok::r_paren))
       Result = Actions.ActOnParenExpr(OpenLoc, Tok.getLocation(), Result.take());
   }
index 6015e918a340e23b39cbfab59409a9f252aa9b37..0d1b6c945c5c0a1aa7dfbaa195638170fe4a5a15 100644 (file)
@@ -51,3 +51,9 @@ int test6(void) {
                test5(1)
                  ; // expected-error {{expected ')'}}
 }
+
+// PR8394
+void test7() {
+    ({} // expected-note {{to match}}
+    ;   // expected-error {{expected ')'}}
+}