diff --git a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp --- a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp @@ -40,8 +40,9 @@ auto StringFind = cxxMemberCallExpr( // .find()-call on a string... - callee(cxxMethodDecl(hasName("find"))), - on(hasType(StringType)), + callee(cxxMethodDecl(hasName("find"))), on(hasType(StringType)), + // ... with 1 or two arguments (but not three), + anyOf(argumentCountIs(1), argumentCountIs(2)), // ... with some search expression ... hasArgument(0, expr().bind("needle")), // ... and either "0" as second argument or the default argument (also 0). diff --git a/clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-startswith.cpp b/clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-startswith.cpp --- a/clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-startswith.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/abseil-string-find-startswith.cpp @@ -13,6 +13,7 @@ ~basic_string(); int find(basic_string s, int pos = 0); int find(const char *s, int pos = 0); + int find(const char *s, int pos, int n); }; typedef basic_string string; typedef basic_string wstring; @@ -41,6 +42,10 @@ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StartsWith // CHECK-FIXES: {{^[[:space:]]*}}absl::StartsWith(s, s);{{$}} + s.find(s, 0) == 0; + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StartsWith + // CHECK-FIXES: {{^[[:space:]]*}}absl::StartsWith(s, s);{{$}} + s.find("aaa") != 0; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StartsWith // CHECK-FIXES: {{^[[:space:]]*}}!absl::StartsWith(s, "aaa");{{$}} @@ -66,4 +71,5 @@ s.find("a", 1) == 0; s.find("a", 1) == 1; s.find("a") == 1; + s.find("a", 0, 1) == 0; }