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; +}; +
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; +}; +
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits