Nathan-Huckleberry updated this revision to Diff 205473. Nathan-Huckleberry added a comment.
Mistakenly updated revision. Attempting to revert. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D63369/new/ https://reviews.llvm.org/D63369 Files: clang/lib/AST/Expr.cpp clang/test/Sema/warn-binary-conditional-expression-unused.c Index: clang/test/Sema/warn-binary-conditional-expression-unused.c =================================================================== --- /dev/null +++ clang/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; +}; + Index: clang/lib/AST/Expr.cpp =================================================================== --- clang/lib/AST/Expr.cpp +++ clang/lib/AST/Expr.cpp @@ -2345,12 +2345,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: clang/test/Sema/warn-binary-conditional-expression-unused.c =================================================================== --- /dev/null +++ clang/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; +}; + Index: clang/lib/AST/Expr.cpp =================================================================== --- clang/lib/AST/Expr.cpp +++ clang/lib/AST/Expr.cpp @@ -2345,12 +2345,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:
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits