[clang-tools-extra] [clang-tidy] support string::contains (PR #110351)

Nicolas van Kempen via cfe-commits cfe-commits at lists.llvm.org
Sat Oct 5 10:37:29 PDT 2024


================
@@ -32,7 +33,8 @@ void ContainerContainsCheck::registerMatchers(MatchFinder *Finder) {
 
   const auto FindCall =
       cxxMemberCallExpr(
-          argumentCountIs(1),
+          anyOf(argumentCountIs(1),
+                allOf(argumentCountIs(2), hasArgument(1, cxxDefaultArgExpr()))),
----------------
nicovank wrote:

Considering `str.find('a') != std::string::npos`. Instead of deleting stuff from `)` to `npos`, you could replace everything from after `'a'` to the end of the comparison with `)`, that should work. I wrote something like this here:
https://github.com/llvm/llvm-project/blob/e8f01b0557354a28d17bfe618df5e257ec3e982a/clang-tools-extra/clang-tidy/modernize/UseStartsEndsWithCheck.cpp#L159-L165

https://github.com/llvm/llvm-project/pull/110351


More information about the cfe-commits mailing list