[cfe-commits] r155762 - in /cfe/trunk: include/clang/Basic/DiagnosticParseKinds.td lib/Parse/ParseStmt.cpp test/Parser/recovery.c
Chris Lattner
sabre at nondot.org
Sat Apr 28 09:24:21 PDT 2012
Author: lattner
Date: Sat Apr 28 11:24:20 2012
New Revision: 155762
URL: http://llvm.org/viewvc/llvm-project?rev=155762&view=rev
Log:
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
Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/lib/Parse/ParseStmt.cpp
cfe/trunk/test/Parser/recovery.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=155762&r1=155761&r2=155762&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Sat Apr 28 11:24:20 2012
@@ -396,6 +396,8 @@
"variable declaration in condition must have an initializer">;
def err_expected_init_in_condition_lparen : Error<
"variable declaration in condition cannot have a parenthesized initializer">;
+def err_extraneous_rparen_in_condition : Error<
+ "extraneous ')' after condition, expected a statement">;
def warn_parens_disambiguated_as_function_decl : Warning<
"parentheses were disambiguated as a function declarator">,
InGroup<VexingParse>;
Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=155762&r1=155761&r2=155762&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Sat Apr 28 11:24:20 2012
@@ -895,6 +895,16 @@
// 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;
}
Modified: cfe/trunk/test/Parser/recovery.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/recovery.c?rev=155762&r1=155761&r2=155762&view=diff
==============================================================================
--- cfe/trunk/test/Parser/recovery.c (original)
+++ cfe/trunk/test/Parser/recovery.c Sat Apr 28 11:24:20 2012
@@ -37,8 +37,9 @@
test(0);
else
;
-
- if (x.i == 0)) // expected-error {{expected expression}}
+
+ // PR12595
+ if (x.i == 0)) // expected-error {{extraneous ')' after condition, expected a statement}}
test(0);
else
;
More information about the cfe-commits
mailing list