diff options
author | Hans Wennborg <hans@hanshq.net> | 2011-09-12 12:07:30 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2011-09-12 12:07:30 +0000 |
commit | cb4d7c202e74783d9c820f155ae27605aa9f5c16 (patch) | |
tree | a97ceaed3f6d2f75ce58fe85279da4d73cfbae1b | |
parent | afc5b15022886c9e9e84d7aa0f2168b83e712310 (diff) |
Silence ?: precendence warning when parenthesis are present.
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
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 5 | ||||
-rw-r--r-- | test/Sema/parentheses.c | 3 | ||||
-rw-r--r-- | test/Sema/parentheses.cpp | 2 |
3 files changed, 7 insertions, 3 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 1828841b30..99c881fe5c 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -4926,9 +4926,10 @@ static bool IsArithmeticOp(BinaryOperatorKind Opc) { /// 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)) { diff --git a/test/Sema/parentheses.c b/test/Sema/parentheses.c index 13ea3ecbe1..9751336018 100644 --- a/test/Sema/parentheses.c +++ b/test/Sema/parentheses.c @@ -52,6 +52,8 @@ void conditional_op(int x, int y, _Bool b) { // 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}} @@ -64,7 +66,6 @@ void conditional_op(int x, int y, _Bool b) { // 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 } diff --git a/test/Sema/parentheses.cpp b/test/Sema/parentheses.cpp index 252455dcad..767416677e 100644 --- a/test/Sema/parentheses.cpp +++ b/test/Sema/parentheses.cpp @@ -40,6 +40,8 @@ void test(S *s, bool (S::*m_ptr)()) { // 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"); } |