Fixes PR10898. The warning should be silent when there are parenthesis
around the condition expression.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139492
91177308-0d34-0410-b5e6-
96231b3b80d8
/// expression.
static bool IsArithmeticBinaryExpr(Expr *E, BinaryOperatorKind *Opcode,
Expr **RHSExprs) {
- E = E->IgnoreParenImpCasts();
+ // Don't strip parenthesis: we should not warn if E is in parenthesis.
+ E = E->IgnoreImpCasts();
E = E->IgnoreConversionOperator();
- E = E->IgnoreParenImpCasts();
+ E = E->IgnoreImpCasts();
// Built-in binary operator.
if (BinaryOperator *OP = dyn_cast<BinaryOperator>(E)) {
// expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
// expected-note {{place parentheses around the '+' expression to silence this warning}}
+ (void)((x + someConditionFunc()) ? 1 : 2); // no warning
+
(void)(x - b ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '-'}} \
// expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
// expected-note {{place parentheses around the '-' expression to silence this warning}}
// expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
// expected-note {{place parentheses around the '/' expression to silence this warning}}
-
(void)(x % 2 ? 1 : 2); // no warning
}
// expected-note {{place parentheses around the '?:' expression to evaluate it first}} \
// expected-note {{place parentheses around the '+' expression to silence this warning}}
+ (void)((*s + true) ? "foo" : "bar"); // No warning.
+
// Don't crash on unusual member call expressions.
(void)((s->*m_ptr)() ? "foo" : "bar");
}