[cfe-commits] r124675 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaCXX/warn-assignment-condition.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Tue Feb 1 11:32:59 PST 2011


Author: akirtzidis
Date: Tue Feb  1 13:32:59 2011
New Revision: 124675

URL: http://llvm.org/viewvc/llvm-project?rev=124675&view=rev
Log:
For "if ((a == b))" only warn if 'a' is a modifiable l-value. Caught by John!

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaCXX/warn-assignment-condition.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=124675&r1=124674&r2=124675&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Feb  1 13:32:59 2011
@@ -9231,7 +9231,9 @@
   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();

Modified: cfe/trunk/test/SemaCXX/warn-assignment-condition.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-assignment-condition.cpp?rev=124675&r1=124674&r2=124675&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-assignment-condition.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-assignment-condition.cpp Tue Feb  1 13:32:59 2011
@@ -109,4 +109,14 @@
   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)) {}
 }





More information about the cfe-commits mailing list