[cfe-commits] r124689 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaCXX/warn-assignment-condition.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Tue Feb 1 14:23:56 PST 2011
Author: akirtzidis
Date: Tue Feb 1 16:23:56 2011
New Revision: 124689
URL: http://llvm.org/viewvc/llvm-project?rev=124689&view=rev
Log:
Don't warn for "if ((a == b))" if the parens came from a macro. Thanks to Fariborz for the hint!
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=124689&r1=124688&r2=124689&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Feb 1 16:23:56 2011
@@ -9228,6 +9228,11 @@
/// \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))
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=124689&r1=124688&r2=124689&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-assignment-condition.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-assignment-condition.cpp Tue Feb 1 16:23:56 2011
@@ -110,6 +110,10 @@
// 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)();
More information about the cfe-commits
mailing list