mirror of https://github.com/microsoft/clang.git
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
This commit is contained in:
parent
8bb21d32e9
commit
bddc7e5ed3
|
@ -396,6 +396,8 @@ def err_expected_init_in_condition : Error<
|
||||||
"variable declaration in condition must have an initializer">;
|
"variable declaration in condition must have an initializer">;
|
||||||
def err_expected_init_in_condition_lparen : Error<
|
def err_expected_init_in_condition_lparen : Error<
|
||||||
"variable declaration in condition cannot have a parenthesized initializer">;
|
"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<
|
def warn_parens_disambiguated_as_function_decl : Warning<
|
||||||
"parentheses were disambiguated as a function declarator">,
|
"parentheses were disambiguated as a function declarator">,
|
||||||
InGroup<VexingParse>;
|
InGroup<VexingParse>;
|
||||||
|
|
|
@ -895,6 +895,16 @@ bool Parser::ParseParenExprOrCondition(ExprResult &ExprResult,
|
||||||
|
|
||||||
// Otherwise the condition is valid or the rparen is present.
|
// Otherwise the condition is valid or the rparen is present.
|
||||||
T.consumeClose();
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,8 +37,9 @@ void test(int a) {
|
||||||
test(0);
|
test(0);
|
||||||
else
|
else
|
||||||
;
|
;
|
||||||
|
|
||||||
if (x.i == 0)) // expected-error {{expected expression}}
|
// PR12595
|
||||||
|
if (x.i == 0)) // expected-error {{extraneous ')' after condition, expected a statement}}
|
||||||
test(0);
|
test(0);
|
||||||
else
|
else
|
||||||
;
|
;
|
||||||
|
|
Loading…
Reference in New Issue