aboutsummaryrefslogtreecommitdiff
path: root/lib/Parse/ParseStmt.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2012-04-28 16:24:20 +0000
committerChris Lattner <sabre@nondot.org>2012-04-28 16:24:20 +0000
commitbddc7e5ed3982b5845e4fbb5d9bc7b7431c35a4f (patch)
treef07ae427142b22a727e2f37f5ecd9fc25d11b21e /lib/Parse/ParseStmt.cpp
parent8bb21d32e9ccc9d9c221506dff26acafa8724cca (diff)
improve error recovery for extra ')'s after a if/switch/while condition. Before:
t.c:3:9: error: expected expression if (x)) { ^ .. which isn't even true - a statement or expression is fine. After: t.c:3:9: error: extraneous ')' after condition, expected a statement if (x)) { ^ This is the second part of PR12595 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155762 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/ParseStmt.cpp')
-rw-r--r--lib/Parse/ParseStmt.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp
index 8dd0a2a5dc..9796ea69ba 100644
--- a/lib/Parse/ParseStmt.cpp
+++ b/lib/Parse/ParseStmt.cpp
@@ -895,6 +895,16 @@ bool Parser::ParseParenExprOrCondition(ExprResult &ExprResult,
// Otherwise the condition is valid or the rparen is present.
T.consumeClose();
+
+ // Check for extraneous ')'s to catch things like "if (foo())) {". We know
+ // that all callers are looking for a statement after the condition, so ")"
+ // isn't valid.
+ while (Tok.is(tok::r_paren)) {
+ Diag(Tok, diag::err_extraneous_rparen_in_condition)
+ << FixItHint::CreateRemoval(Tok.getLocation());
+ ConsumeParen();
+ }
+
return false;
}