Don't warn for "if ((a == b))" if the parens came from a macro. Thanks to Fariborz for the hint!

llvm-svn: 124689
This commit is contained in:
Argyrios Kyrtzidis 2011-02-01 22:23:56 +00:00
parent 29c8c8fe92
commit f4f8278c95
2 changed files with 9 additions and 0 deletions

View 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))

View 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)();