summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp29
1 files changed, 14 insertions, 15 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
index 548fed9a47c3..d399c957c7c7 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
@@ -218,23 +218,22 @@ void ContainerSizeEmptyCheck::check(const MatchFinder::MatchResult &Result) {
Hint = FixItHint::CreateReplacement(BinCmpRewritten->getSourceRange(),
ReplacementText);
} else if (BinaryOp) { // Determine the correct transformation.
+ const auto *LiteralLHS =
+ llvm::dyn_cast<IntegerLiteral>(BinaryOp->getLHS()->IgnoreImpCasts());
+ const auto *LiteralRHS =
+ llvm::dyn_cast<IntegerLiteral>(BinaryOp->getRHS()->IgnoreImpCasts());
+ const bool ContainerIsLHS = !LiteralLHS;
+
+ uint64_t Value = 0;
+ if (LiteralLHS)
+ Value = LiteralLHS->getValue().getLimitedValue();
+ else if (LiteralRHS)
+ Value = LiteralRHS->getValue().getLimitedValue();
+ else
+ return;
+
bool Negation = false;
- const bool ContainerIsLHS =
- !llvm::isa<IntegerLiteral>(BinaryOp->getLHS()->IgnoreImpCasts());
const auto OpCode = BinaryOp->getOpcode();
- uint64_t Value = 0;
- if (ContainerIsLHS) {
- if (const auto *Literal = llvm::dyn_cast<IntegerLiteral>(
- BinaryOp->getRHS()->IgnoreImpCasts()))
- Value = Literal->getValue().getLimitedValue();
- else
- return;
- } else {
- Value =
- llvm::dyn_cast<IntegerLiteral>(BinaryOp->getLHS()->IgnoreImpCasts())
- ->getValue()
- .getLimitedValue();
- }
// Constant that is not handled.
if (Value > 1)