[clang-tools-extra] [clang-tidy][readability-container-contains] Extend to any class with contains (PR #107521)
Julian Schmidt via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 6 07:39:42 PDT 2024
================
@@ -15,26 +15,26 @@ using namespace clang::ast_matchers;
namespace clang::tidy::readability {
void ContainerContainsCheck::registerMatchers(MatchFinder *Finder) {
- const auto SupportedContainers = hasType(
- hasUnqualifiedDesugaredType(recordType(hasDeclaration(cxxRecordDecl(
- hasAnyName("::std::set", "::std::unordered_set", "::std::map",
- "::std::unordered_map", "::std::multiset",
- "::std::unordered_multiset", "::std::multimap",
- "::std::unordered_multimap"))))));
+ const auto HasContainsMethod = hasMethod(
+ cxxMethodDecl(isConst(), returns(booleanType()), hasName("contains")));
+ const auto ContainerWithContains = hasType(
+ hasUnqualifiedDesugaredType(recordType(hasDeclaration(cxxRecordDecl(anyOf(
+ HasContainsMethod, hasAnyBase(hasType(hasCanonicalType(hasDeclaration(
+ cxxRecordDecl(HasContainsMethod)))))))))));
----------------
5chmidti wrote:
I'd go even further with checking if the `contains` function is possible to use: check that the function is not deleted, and check if the type of the parameter from the called method and that of the `contains` function are equal.
https://github.com/llvm/llvm-project/pull/107521
More information about the cfe-commits
mailing list