aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Sema/SemaExpr.cpp5
-rw-r--r--test/SemaCXX/warn-assignment-condition.cpp4
2 files changed, 9 insertions, 0 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 8448ed8079..6fe111fac7 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -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))
diff --git a/test/SemaCXX/warn-assignment-condition.cpp b/test/SemaCXX/warn-assignment-condition.cpp
index 6cfab55440..7596bb26ae 100644
--- a/test/SemaCXX/warn-assignment-condition.cpp
+++ b/test/SemaCXX/warn-assignment-condition.cpp
@@ -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)();