summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST
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
commite96dad9544f0f87dc65ba097f4fb05b25a3fb804 (patch)
tree2f344c42ac8a51b64b1b85891d0e8773a08a7632 /clang/lib/AST
parenta7a795bed1fd104b162add53a8ab15e163f6648f (diff)
downloadbcm5719-llvm-e96dad9544f0f87dc65ba097f4fb05b25a3fb804.tar.gz
bcm5719-llvm-e96dad9544f0f87dc65ba097f4fb05b25a3fb804.zip
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. llvm-svn: 126779
Diffstat (limited to 'clang/lib/AST')
-rw-r--r--clang/lib/AST/Expr.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 8e44c073682..930457c249c 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/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:
OpenPOWER on IntegriCloud