]> granicus.if.org Git - clang/commitdiff
Don't warn for "if ((a == b))" if the parens came from a macro. Thanks to Fariborz...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 1 Feb 2011 22:23:56 +0000 (22:23 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 1 Feb 2011 22:23:56 +0000 (22:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124689 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/SemaCXX/warn-assignment-condition.cpp

index 8448ed80793a2401c11faa5019e03fa851ef4550..6fe111fac73c2815c147e37844ea4825c95e5b6f 100644 (file)
@@ -9228,6 +9228,11 @@ void Sema::DiagnoseAssignmentAsCondition(Expr *E) {
 /// \brief Redundant parentheses over an equality comparison can indicate
 /// that the user intended an assignment used as condition.
 void Sema::DiagnoseEqualityWithExtraParens(ParenExpr *parenE) {
+  // Don't warn if the parens came from a macro.
+  SourceLocation parenLoc = parenE->getLocStart();
+  if (parenLoc.isInvalid() || parenLoc.isMacroID())
+    return;
+
   Expr *E = parenE->IgnoreParens();
 
   if (BinaryOperator *opE = dyn_cast<BinaryOperator>(E))
index 6cfab5544027441d9b4052d1f8f7e55314515fd3..7596bb26aeaa4facc7ba108f72f35e0bb6d4d859 100644 (file)
@@ -110,6 +110,10 @@ void test() {
                    // 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)) {}
+
+#define EQ(x,y) ((x) == (y))
+  if (EQ(x, 5)) {}
+#undef EQ
 }
 
 void (*fn)();