summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp26
1 files changed, 16 insertions, 10 deletions
diff --git a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
index 5167315dea4..3cec1fb935d 100644
--- a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -555,10 +555,14 @@ static bool areSidesBinaryConstExpressions(const BinaryOperator *&BinOp, const A
if (!LhsBinOp || !RhsBinOp)
return false;
- if ((LhsBinOp->getLHS()->isIntegerConstantExpr(*AstCtx) ||
- LhsBinOp->getRHS()->isIntegerConstantExpr(*AstCtx)) &&
- (RhsBinOp->getLHS()->isIntegerConstantExpr(*AstCtx) ||
- RhsBinOp->getRHS()->isIntegerConstantExpr(*AstCtx)))
+ auto IsIntegerConstantExpr = [AstCtx](const Expr *E) {
+ return !E->isValueDependent() && E->isIntegerConstantExpr(*AstCtx);
+ };
+
+ if ((IsIntegerConstantExpr(LhsBinOp->getLHS()) ||
+ IsIntegerConstantExpr(LhsBinOp->getRHS())) &&
+ (IsIntegerConstantExpr(RhsBinOp->getLHS()) ||
+ IsIntegerConstantExpr(RhsBinOp->getRHS())))
return true;
return false;
}
@@ -580,12 +584,14 @@ static bool retrieveConstExprFromBothSides(const BinaryOperator *&BinOp,
const auto *BinOpLhs = cast<BinaryOperator>(BinOp->getLHS());
const auto *BinOpRhs = cast<BinaryOperator>(BinOp->getRHS());
- LhsConst = BinOpLhs->getLHS()->isIntegerConstantExpr(*AstCtx)
- ? BinOpLhs->getLHS()
- : BinOpLhs->getRHS();
- RhsConst = BinOpRhs->getLHS()->isIntegerConstantExpr(*AstCtx)
- ? BinOpRhs->getLHS()
- : BinOpRhs->getRHS();
+ auto IsIntegerConstantExpr = [AstCtx](const Expr *E) {
+ return !E->isValueDependent() && E->isIntegerConstantExpr(*AstCtx);
+ };
+
+ LhsConst = IsIntegerConstantExpr(BinOpLhs->getLHS()) ? BinOpLhs->getLHS()
+ : BinOpLhs->getRHS();
+ RhsConst = IsIntegerConstantExpr(BinOpRhs->getLHS()) ? BinOpRhs->getLHS()
+ : BinOpRhs->getRHS();
if (!LhsConst || !RhsConst)
return false;
OpenPOWER on IntegriCloud