[clang-tools-extra] [clang-tidy] rewrite matchers in modernize-use-starts-ends-with (PR #112101)
Nicolas van Kempen via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 12 11:32:08 PDT 2024
================
@@ -150,8 +150,8 @@ void test(std::string s, std::string_view sv, sub_string ss, sub_sub_string sss,
// CHECK-FIXES: puv.starts_with("a");
puvf.find("a") == 0;
- // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
- // CHECK-FIXES: puvf.starts_with("a");
+ // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use startsWith
+ // CHECK-FIXES: puvf.startsWith("a");
----------------
nicovank wrote:
I kinda liked the idea of preferring `starts_with` over others.
e.g. `llvm::StringRef` used to have the `startswith` overload until 4ec9a662d388db8a2bb862dbaa7fc3fd809d1240, `folly::StringPiece` still uses `startsWith`: [folly/Range.h](https://github.com/facebook/folly/blob/0aa6ed46b941d384214b9a0cdf9b339bf68913c6/folly/Range.h#L973-L989)
I feel like most projects are likely to move towards `starts_with` to match standard if multiple overloads are present, so might as well recommend it with higher priority. What do you think?
Suggestion to keep ordering, merged with other suggestion above to remove and simplify out the desugar/subclass logic:
```
const auto ClassTypeWithMethod = [](const StringRef MethodBoundName,
auto... MethodName) {
return cxxRecordDecl(anyOf(
hasMethod(cxxMethodDecl(isConst(), parameterCountIs(1),
returns(booleanType()), hasName(MethodName))
.bind(MethodBoundName))...));
};
```
https://github.com/llvm/llvm-project/pull/112101
More information about the cfe-commits
mailing list