White-list comma expressions with the literal 0 as their RHS against
unused-value warnings. This is a common macro idiom.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96326 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
index 22eb28c..4cb0aa4 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -827,9 +827,17 @@
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)
+ 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->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx) ||
BO->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx));
+ }
if (BO->isAssignmentOp())
return false;