Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,44 +62,44 @@ void ContainerContainsCheck::registerMatchers(MatchFinder *Finder) {
.bind("positiveComparison"),
this);
AddSimpleMatcher(
binaryOperator(hasOperatorName("!="), hasOperands(CountCall, Literal0))
binaryOperation(hasOperatorName("!="), hasOperands(CountCall, Literal0))
.bind("positiveComparison"));
AddSimpleMatcher(
binaryOperator(hasLHS(CountCall), hasOperatorName(">"), hasRHS(Literal0))
binaryOperation(hasLHS(CountCall), hasOperatorName(">"), hasRHS(Literal0))
.bind("positiveComparison"));
AddSimpleMatcher(
binaryOperator(hasLHS(Literal0), hasOperatorName("<"), hasRHS(CountCall))
.bind("positiveComparison"));
AddSimpleMatcher(
binaryOperator(hasLHS(CountCall), hasOperatorName(">="), hasRHS(Literal1))
.bind("positiveComparison"));
AddSimpleMatcher(
binaryOperator(hasLHS(Literal1), hasOperatorName("<="), hasRHS(CountCall))
binaryOperation(hasLHS(Literal0), hasOperatorName("<"), hasRHS(CountCall))
.bind("positiveComparison"));
AddSimpleMatcher(binaryOperation(hasLHS(CountCall), hasOperatorName(">="),
hasRHS(Literal1))
.bind("positiveComparison"));
AddSimpleMatcher(binaryOperation(hasLHS(Literal1), hasOperatorName("<="),
hasRHS(CountCall))
.bind("positiveComparison"));

// Find inverted membership tests which use `count()`.
AddSimpleMatcher(
binaryOperator(hasOperatorName("=="), hasOperands(CountCall, Literal0))
.bind("negativeComparison"));
AddSimpleMatcher(
binaryOperator(hasLHS(CountCall), hasOperatorName("<="), hasRHS(Literal0))
.bind("negativeComparison"));
AddSimpleMatcher(
binaryOperator(hasLHS(Literal0), hasOperatorName(">="), hasRHS(CountCall))
binaryOperation(hasOperatorName("=="), hasOperands(CountCall, Literal0))
.bind("negativeComparison"));
AddSimpleMatcher(binaryOperation(hasLHS(CountCall), hasOperatorName("<="),
hasRHS(Literal0))
.bind("negativeComparison"));
AddSimpleMatcher(binaryOperation(hasLHS(Literal0), hasOperatorName(">="),
hasRHS(CountCall))
.bind("negativeComparison"));
AddSimpleMatcher(
binaryOperator(hasLHS(CountCall), hasOperatorName("<"), hasRHS(Literal1))
binaryOperation(hasLHS(CountCall), hasOperatorName("<"), hasRHS(Literal1))
.bind("negativeComparison"));
AddSimpleMatcher(
binaryOperator(hasLHS(Literal1), hasOperatorName(">"), hasRHS(CountCall))
binaryOperation(hasLHS(Literal1), hasOperatorName(">"), hasRHS(CountCall))
.bind("negativeComparison"));

// Find membership tests based on `find() == end()`.
AddSimpleMatcher(
binaryOperator(hasOperatorName("!="), hasOperands(FindCall, EndCall))
binaryOperation(hasOperatorName("!="), hasOperands(FindCall, EndCall))
.bind("positiveComparison"));
AddSimpleMatcher(
binaryOperator(hasOperatorName("=="), hasOperands(FindCall, EndCall))
binaryOperation(hasOperatorName("=="), hasOperands(FindCall, EndCall))
.bind("negativeComparison"));
}

Expand Down
3 changes: 2 additions & 1 deletion clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ Changes in existing checks

- Improved :doc:`readability-container-contains
<clang-tidy/checks/readability/container-contains>` check to let it work on
any class that has a ``contains`` method.
any class that has a ``contains`` method. Fix some false negatives in the
``find()`` case.

- Improved :doc:`readability-enum-initial-value
<clang-tidy/checks/readability/enum-initial-value>` check by only issuing
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
// RUN: %check_clang_tidy -std=c++20-or-later %s readability-container-contains %t
// RUN: %check_clang_tidy -std=c++11-or-later %s readability-container-contains %t

// Some *very* simplified versions of `map` etc.
namespace std {

template <class Key, class T>
struct map {
struct iterator {
bool operator==(const iterator &Other) const;
bool operator!=(const iterator &Other) const;
};

unsigned count(const Key &K) const;
bool contains(const Key &K) const;
void *find(const Key &K);
void *end();
iterator find(const Key &K);
iterator end();
};

template <class Key>
Expand Down
Loading