aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/Expr.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2011-03-01 20:34:48 +0000
committerTed Kremenek <kremenek@apple.com>2011-03-01 20:34:48 +0000
commitfb7cb35fa0a8131853b1b049ca7be77980e144f5 (patch)
treefa3b015d9dc00e2aae37c3f71885a255214a73dd /lib/AST/Expr.cpp
parent94fdffa4a572fc14ac296f5f1aae9db3734c72f1 (diff)
Don't warn about unused values in ternary ?: expressions unless both the LHS and RHS are "unused" (side-effect free).
Patch by Justin Bogner! Fixes PR 8282. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126779 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Expr.cpp')
-rw-r--r--lib/AST/Expr.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
index 8e44c07368..930457c249 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -1404,13 +1404,15 @@ bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
return false;
case ConditionalOperatorClass: {
- // The condition must be evaluated, but if either the LHS or RHS is a
- // warning, warn about them.
+ // If only one of the LHS or RHS is a warning, the operator might
+ // be being used for control flow. Only warn if both the LHS and
+ // RHS are warnings.
const ConditionalOperator *Exp = cast<ConditionalOperator>(this);
- if (Exp->getLHS() &&
- Exp->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx))
+ if (!Exp->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx))
+ return false;
+ if (!Exp->getLHS())
return true;
- return Exp->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx);
+ return Exp->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx);
}
case MemberExprClass: