[clang-tools-extra] [clang-tidy] Support find for string-like classes in readability-container-contains (PR #157243)
Nicolas van Kempen via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 8 11:33:58 PDT 2025
================
@@ -318,17 +321,15 @@ void testPrivateContains(CustomMapPrivateContains<int, int> &MyMap,
if (MyMap2.count(0)) {};
}
-struct MyString {};
-
struct WeirdNonMatchingContains {
unsigned count(char) const;
- bool contains(const MyString&) const;
+ bool contains(const std::string&) const;
};
-void testWeirdNonMatchingContains(WeirdNonMatchingContains &MyMap) {
- // No warning if there is no `contains` method with the right type.
- if (MyMap.count('a')) {};
-}
+// False positives: when count/find and contains take different types,
+// the check will suggest an invalid code transformation. These cases
+// should not exist in real code or be rare enough.
+// void f(WeirdNonMatchingContains MyMap) { MyMap.count('a'); }
----------------
nicovank wrote:
Checked a few cases from [this search](https://github.com/search?q=repo%3Allvm%2Fllvm-project+PATH%3Aclang-tools-extra%2Ftest%2Fclang-tidy%2Fcheckers+%22false+positive%22&type=code) and seems like that's right! Changing.
https://github.com/llvm/llvm-project/pull/157243
More information about the cfe-commits
mailing list