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.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
index f194b47ad90..56396156e6a 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
@@ -16,6 +16,7 @@ using namespace clang::ast_matchers;
static bool isContainerName(llvm::StringRef ClassName) {
static const char *const ContainerNames[] = {"array",
+ "basic_string",
"deque",
"forward_list",
"list",
@@ -59,14 +60,13 @@ void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) {
return;
const auto WrongUse = anyOf(
- hasParent(
- binaryOperator(
- anyOf(has(integerLiteral(equals(0))),
- allOf(anyOf(hasOperatorName("<"), hasOperatorName(">="),
- hasOperatorName(">"), hasOperatorName("<=")),
- hasEitherOperand(
- ignoringImpCasts(integerLiteral(equals(1)))))))
- .bind("SizeBinaryOp")),
+ hasParent(binaryOperator(
+ anyOf(hasOperatorName("<"), hasOperatorName(">="),
+ hasOperatorName(">"), hasOperatorName("<="),
+ hasOperatorName("=="), hasOperatorName("!=")),
+ hasEitherOperand(ignoringImpCasts(anyOf(
+ integerLiteral(equals(1)), integerLiteral(equals(0))))))
+ .bind("SizeBinaryOp")),
hasParent(implicitCastExpr(
hasImplicitDestinationType(booleanType()),
anyOf(
@@ -122,6 +122,10 @@ void ContainerSizeEmptyCheck::check(const MatchFinder::MatchResult &Result) {
if (Value > 1)
return;
+ if (Value == 1 && (OpCode == BinaryOperatorKind::BO_EQ ||
+ OpCode == BinaryOperatorKind::BO_NE))
+ return;
+
// Always true, no warnings for that.
if ((OpCode == BinaryOperatorKind::BO_GE && Value == 0 && ContainerIsLHS) ||
(OpCode == BinaryOperatorKind::BO_LE && Value == 0 && !ContainerIsLHS))
OpenPOWER on IntegriCloud