summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/Expr.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-04-07 18:49:21 +0000
committerTed Kremenek <kremenek@apple.com>2010-04-07 18:49:21 +0000
commit43a9c9626faef1eb45f2be116b2b74eb3a591acd (patch)
treef5f8aa0862993817b9d2c15d0cd1d7fe17930f61 /clang/lib/AST/Expr.cpp
parent198cb4df6e583e8bf74aca570cf657577164f239 (diff)
downloadbcm5719-llvm-43a9c9626faef1eb45f2be116b2b74eb3a591acd.tar.gz
bcm5719-llvm-43a9c9626faef1eb45f2be116b2b74eb3a591acd.zip
Don't emit an 'unused expression' warning for '||' and '&&' expressions that contain assignments
or similar side-effects. llvm-svn: 100676
Diffstat (limited to 'clang/lib/AST/Expr.cpp')
-rw-r--r--clang/lib/AST/Expr.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 132245e671c..9c8de6bf9c8 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -837,19 +837,22 @@ bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
}
case BinaryOperatorClass: {
const BinaryOperator *BO = cast<BinaryOperator>(this);
- // Consider comma to have side effects if the LHS or RHS does.
- if (BO->getOpcode() == BinaryOperator::Comma) {
- // ((foo = <blah>), 0) is an idiom for hiding the result (and
- // lvalue-ness) of an assignment written in a macro.
- if (IntegerLiteral *IE =
- dyn_cast<IntegerLiteral>(BO->getRHS()->IgnoreParens()))
- if (IE->getValue() == 0)
- return false;
-
- return (BO->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx) ||
- BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx));
+ switch (BO->getOpcode()) {
+ default:
+ break;
+ // Consider ',', '||', '&&' to have side effects if the LHS or RHS does.
+ case BinaryOperator::Comma:
+ // ((foo = <blah>), 0) is an idiom for hiding the result (and
+ // lvalue-ness) of an assignment written in a macro.
+ if (IntegerLiteral *IE =
+ dyn_cast<IntegerLiteral>(BO->getRHS()->IgnoreParens()))
+ if (IE->getValue() == 0)
+ return false;
+ case BinaryOperator::LAnd:
+ case BinaryOperator::LOr:
+ return (BO->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx) ||
+ BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx));
}
-
if (BO->isAssignmentOp())
return false;
Loc = BO->getOperatorLoc();
OpenPOWER on IntegriCloud