r363857 - [AST] Fixed extraneous warnings for binary conditional operator
Nathan Huckleberry via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 19 11:37:01 PDT 2019
Author: nathan-huckleberry
Date: Wed Jun 19 11:37:01 2019
New Revision: 363857
URL: http://llvm.org/viewvc/llvm-project?rev=363857&view=rev
Log:
[AST] Fixed extraneous warnings for binary conditional operator
Summary:
Binary conditional operator gave warnings where ternary operators
did not. They have been fixed to warn similarly to ternary operators.
Link: https://bugs.llvm.org/show_bug.cgi?id=42239
Reviewers: rsmith, aaron.ballman, nickdesaulniers
Reviewed By: rsmith, nickdesaulniers
Subscribers: srhines, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D63369
Added:
cfe/trunk/test/Sema/warn-binary-conditional-expression-unused.c
Modified:
cfe/trunk/lib/AST/Expr.cpp
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=363857&r1=363856&r2=363857&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Wed Jun 19 11:37:01 2019
@@ -2453,12 +2453,13 @@ bool Expr::isUnusedResultAWarning(const
// 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:
Added: cfe/trunk/test/Sema/warn-binary-conditional-expression-unused.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-binary-conditional-expression-unused.c?rev=363857&view=auto
==============================================================================
--- cfe/trunk/test/Sema/warn-binary-conditional-expression-unused.c (added)
+++ cfe/trunk/test/Sema/warn-binary-conditional-expression-unused.c Wed Jun 19 11:37:01 2019
@@ -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;
+};
+
More information about the cfe-commits
mailing list