[clang-tools-extra] [clang-tidy] Enhance modernize-use-starts-ends-with to handle substr patterns (PR #116033)
Helmut Januschka via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 18 01:38:11 PST 2024
================
@@ -36,221 +36,224 @@ void test(std::string s, std::string_view sv, sub_string ss, sub_sub_string sss,
string_like sl, string_like_camel slc, prefer_underscore_version puv,
prefer_underscore_version_flip puvf) {
s.find("a") == 0;
- // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with instead of find() == 0
+ // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with instead of find == [modernize-use-starts-ends-with]
----------------
hjanuschka wrote:
ok got you, reverted tests, but to prevent showing:
```
use starts_with instead of substr() == 0
```
a small change is needed.
```
auto Diag = diag(FindExpr->getExprLoc(),
FindFun->getName() == "substr"
? "use %0 instead of %1() %select{==|!=}2"
: "use %0 instead of %1() %select{==|!=}2 0")
<< ReplacementFunction->getName() << FindFun->getName() << Neg;
```
but this makes sure the old tests are unchanged.
https://github.com/llvm/llvm-project/pull/116033
More information about the cfe-commits
mailing list