diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-04-07 18:49:21 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-04-07 18:49:21 +0000 |
commit | c46a246f5fb00bf8448a1081e7d7e73bb6dbfbf5 (patch) | |
tree | cd5399dd1d40797d72eafd3d57969fb334c204d9 /lib/AST/Expr.cpp | |
parent | 53eee7ba970d21ff15bbd4334164037a3b4cc4b8 (diff) |
Don't emit an 'unused expression' warning for '||' and '&&' expressions that contain assignments
or similar side-effects.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100676 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Expr.cpp')
-rw-r--r-- | lib/AST/Expr.cpp | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 132245e671..9c8de6bf9c 100644 --- a/lib/AST/Expr.cpp +++ b/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(); |