summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp51
-rw-r--r--clang-tools-extra/test/clang-tidy/readability-container-size-empty.cpp2
2 files changed, 27 insertions, 26 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
index 39002041bff..87ba314411c 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
@@ -15,24 +15,22 @@
using namespace clang::ast_matchers;
static bool isContainer(llvm::StringRef ClassName) {
- static const char *const ContainerNames[] = {
- "std::array",
- "std::deque",
- "std::forward_list",
- "std::list",
- "std::map",
- "std::multimap",
- "std::multiset",
- "std::priority_queue",
- "std::queue",
- "std::set",
- "std::stack",
- "std::unordered_map",
- "std::unordered_multimap",
- "std::unordered_multiset",
- "std::unordered_set",
- "std::vector"
- };
+ static const char *const ContainerNames[] = {"std::array",
+ "std::deque",
+ "std::forward_list",
+ "std::list",
+ "std::map",
+ "std::multimap",
+ "std::multiset",
+ "std::priority_queue",
+ "std::queue",
+ "std::set",
+ "std::stack",
+ "std::unordered_map",
+ "std::unordered_multimap",
+ "std::unordered_multiset",
+ "std::unordered_set",
+ "std::vector"};
return std::binary_search(std::begin(ContainerNames),
std::end(ContainerNames), ClassName);
}
@@ -65,7 +63,8 @@ void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) {
anyOf(has(integerLiteral(equals(0))),
allOf(anyOf(hasOperatorName("<"), hasOperatorName(">="),
hasOperatorName(">"), hasOperatorName("<=")),
- hasEitherOperand(integerLiteral(equals(1))))))
+ hasEitherOperand(
+ ignoringImpCasts(integerLiteral(equals(1)))))))
.bind("SizeBinaryOp")),
hasParent(implicitCastExpr(
hasImplicitDestinationType(isBoolType()),
@@ -101,19 +100,21 @@ void ContainerSizeEmptyCheck::check(const MatchFinder::MatchResult &Result) {
if (BinaryOp) { // Determine the correct transformation.
bool Negation = false;
- const bool ContainerIsLHS = !llvm::isa<IntegerLiteral>(BinaryOp->getLHS());
+ 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()))
+ 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())
- ->getValue()
- .getLimitedValue();
+ Value =
+ llvm::dyn_cast<IntegerLiteral>(BinaryOp->getLHS()->IgnoreImpCasts())
+ ->getValue()
+ .getLimitedValue();
}
// Constant that is not handled.
diff --git a/clang-tools-extra/test/clang-tidy/readability-container-size-empty.cpp b/clang-tools-extra/test/clang-tidy/readability-container-size-empty.cpp
index 652c114a281..d7f2612b57d 100644
--- a/clang-tools-extra/test/clang-tidy/readability-container-size-empty.cpp
+++ b/clang-tools-extra/test/clang-tidy/readability-container-size-empty.cpp
@@ -3,7 +3,7 @@
namespace std {
template <typename T> struct vector {
vector() {}
- int size() const {}
+ unsigned long size() const {}
bool empty() const {}
};
}
OpenPOWER on IntegriCloud