[clang-tools-extra] [clang-tidy] Enhance modernize-use-starts-ends-with to handle substr patterns (PR #116033)
Congcong Cai via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 17 17:55:02 PST 2024
================
@@ -171,10 +182,64 @@ void UseStartsEndsWithCheck::registerMatchers(MatchFinder *Finder) {
hasRHS(lengthExprForStringNode("needle")))))
.bind("expr"),
this);
+
+ Finder->addMatcher(
+ cxxOperatorCallExpr(
+ hasAnyOperatorName("==", "!="),
+ anyOf(
+ hasOperands(
+ cxxMemberCallExpr(
+ argumentCountIs(2), hasArgument(0, ZeroLiteral),
+ hasArgument(1, lengthExprForStringNode("needle")),
+ callee(
+ cxxMethodDecl(hasName("substr"),
+ ofClass(OnClassWithStartsWithFunction))
+ .bind("find_fun")))
+ .bind("find_expr"),
+ expr().bind("needle")),
+ hasOperands(expr().bind("needle"),
+ cxxMemberCallExpr(
+ argumentCountIs(2), hasArgument(0, ZeroLiteral),
+ hasArgument(1, lengthExprForStringNode("needle")),
+ callee(cxxMethodDecl(
+ hasName("substr"),
+ ofClass(OnClassWithStartsWithFunction))
+ .bind("find_fun")))
+ .bind("find_expr"))))
+ .bind("expr"),
+ this);
+}
+
+bool UseStartsEndsWithCheck::isNegativeComparison(const Expr* ComparisonExpr) {
----------------
HerrCai0907 wrote:
This function don't need to be exposed. it could be static function instead of class method to save the build time.
https://github.com/llvm/llvm-project/pull/116033
More information about the cfe-commits
mailing list