[PATCH] D63369: [AST] Fixed extraneous warnings for binary conditional operator

Nathan Huckleberry via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 19 11:34:26 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL363857: [AST] Fixed extraneous warnings for binary conditional operator (authored by Nathan-Huckleberry, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63369?vs=205473&id=205652#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63369/new/

https://reviews.llvm.org/D63369

Files:
  cfe/trunk/lib/AST/Expr.cpp
  cfe/trunk/test/Sema/warn-binary-conditional-expression-unused.c


Index: cfe/trunk/lib/AST/Expr.cpp
===================================================================
--- cfe/trunk/lib/AST/Expr.cpp
+++ cfe/trunk/lib/AST/Expr.cpp
@@ -2453,12 +2453,13 @@
     // If only one of the LHS or RHS is a warning, the operator might
     // be being used for control flow. Only warn if both the LHS and
     // RHS are warnings.
-    const ConditionalOperator *Exp = cast<ConditionalOperator>(this);
-    if (!Exp->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx))
-      return false;
-    if (!Exp->getLHS())
-      return true;
-    return Exp->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
+    const auto *Exp = cast<ConditionalOperator>(this);
+    return Exp->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx) &&
+           Exp->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
+  }
+  case BinaryConditionalOperatorClass: {
+    const auto *Exp = cast<BinaryConditionalOperator>(this);
+    return Exp->getFalseExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
   }
 
   case MemberExprClass:
Index: cfe/trunk/test/Sema/warn-binary-conditional-expression-unused.c
===================================================================
--- cfe/trunk/test/Sema/warn-binary-conditional-expression-unused.c
+++ cfe/trunk/test/Sema/warn-binary-conditional-expression-unused.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunused-value -verify %s
+int main() {
+    int a;
+    int b;
+    a ? : b; //expected-warning{{expression result unused}}
+    a ? a : b; //expected-warning{{expression result unused}}
+    a ? : ++b;
+    a ? a : ++b;
+    ++a ? : b; //expected-warning{{expression result unused}}
+    ++a ? a : b; //expected-warning{{expression result unused}}
+    ++a ? : ++b;
+    ++a ? a : ++b;
+    return 0;
+};
+


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63369.205652.patch
Type: text/x-patch
Size: 1810 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190619/5bf51e39/attachment.bin>


More information about the cfe-commits mailing list