From ae7a834e74e19f34b87c6546f5017ebb719bbad3 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 1 Dec 2007 06:07:34 +0000 Subject: [PATCH] make the unused expression warning less noisy by not warning about comma exprs whose LHS and RHS both have side effects. llvm-svn: 44486 --- clang/AST/Expr.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/clang/AST/Expr.cpp b/clang/AST/Expr.cpp index 15fbb24a0d41..5871a5c86825 100644 --- a/clang/AST/Expr.cpp +++ b/clang/AST/Expr.cpp @@ -243,8 +243,15 @@ bool Expr::hasLocalSideEffect() const { return UO->getSubExpr()->hasLocalSideEffect(); } } - case BinaryOperatorClass: - return cast(this)->isAssignmentOp(); + case BinaryOperatorClass: { + const BinaryOperator *BinOp = cast(this); + // Consider comma to have side effects if the LHS and RHS both do. + if (BinOp->getOpcode() == BinaryOperator::Comma) + return BinOp->getLHS()->hasLocalSideEffect() && + BinOp->getRHS()->hasLocalSideEffect(); + + return BinOp->isAssignmentOp(); + } case CompoundAssignOperatorClass: return true;