[cfe-commits] r139492 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/Sema/parentheses.c test/Sema/parentheses.cpp
Hans Wennborg
hans at hanshq.net
Mon Sep 12 05:07:30 PDT 2011
Author: hans
Date: Mon Sep 12 07:07:30 2011
New Revision: 139492
URL: http://llvm.org/viewvc/llvm-project?rev=139492&view=rev
Log:
Silence ?: precendence warning when parenthesis are present.
Fixes PR10898. The warning should be silent when there are parenthesis
around the condition expression.
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/parentheses.c
cfe/trunk/test/Sema/parentheses.cpp
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=139492&r1=139491&r2=139492&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Sep 12 07:07:30 2011
@@ -4926,9 +4926,10 @@
/// 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)) {
Modified: cfe/trunk/test/Sema/parentheses.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/parentheses.c?rev=139492&r1=139491&r2=139492&view=diff
==============================================================================
--- cfe/trunk/test/Sema/parentheses.c (original)
+++ cfe/trunk/test/Sema/parentheses.c Mon Sep 12 07:07:30 2011
@@ -52,6 +52,8 @@
// 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 @@
// 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
}
Modified: cfe/trunk/test/Sema/parentheses.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/parentheses.cpp?rev=139492&r1=139491&r2=139492&view=diff
==============================================================================
--- cfe/trunk/test/Sema/parentheses.cpp (original)
+++ cfe/trunk/test/Sema/parentheses.cpp Mon Sep 12 07:07:30 2011
@@ -40,6 +40,8 @@
// 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");
}
More information about the cfe-commits
mailing list