For "if ((a == b))" only warn if 'a' is a modifiable l-value. Caught by John!

llvm-svn: 124675
This commit is contained in:
Argyrios Kyrtzidis 2011-02-01 19:32:59 +00:00
parent 15a3daa189
commit 582dd68541
2 changed files with 13 additions and 1 deletions

View File

@ -9231,7 +9231,9 @@ void Sema::DiagnoseEqualityWithExtraParens(ParenExpr *parenE) {
Expr *E = parenE->IgnoreParens();
if (BinaryOperator *opE = dyn_cast<BinaryOperator>(E))
if (opE->getOpcode() == BO_EQ) {
if (opE->getOpcode() == BO_EQ &&
opE->getLHS()->IgnoreParenImpCasts()->isModifiableLvalue(Context)
== Expr::MLV_Valid) {
SourceLocation Loc = opE->getOperatorLoc();
Diag(Loc, diag::warn_equality_with_extra_parens) << E->getSourceRange();

View File

@ -109,4 +109,14 @@ void test() {
if ((x == 5)) {} // expected-warning {{equality comparison with extraneous parentheses}} \
// expected-note {{use '=' to turn this equality comparison into an assignment}} \
// expected-note {{remove extraneous parentheses around the comparison to silence this warning}}
if ((5 == x)) {}
}
void (*fn)();
void test2() {
if ((fn == test2)) {} // expected-warning {{equality comparison with extraneous parentheses}} \
// expected-note {{use '=' to turn this equality comparison into an assignment}} \
// expected-note {{remove extraneous parentheses around the comparison to silence this warning}}
if ((test2 == fn)) {}
}