]> granicus.if.org Git - clang/commitdiff
White-list comma expressions with the literal 0 as their RHS against
authorJohn McCall <rjmccall@apple.com>
Tue, 16 Feb 2010 04:10:53 +0000 (04:10 +0000)
committerJohn McCall <rjmccall@apple.com>
Tue, 16 Feb 2010 04:10:53 +0000 (04:10 +0000)
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

lib/AST/Expr.cpp

index 22eb28c3599843a25a5f16a30f68f584f937cbd1..4cb0aa4560deaf2cb2c68eda4c61b534d648a48f 100644 (file)
@@ -827,9 +827,17 @@ 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)
+    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;