================
@@ -49,56 +47,38 @@ void 
StringViewConversionsCheck::registerMatchers(MatchFinder *Finder) {
   const auto RedundantFunctionalCast = cxxFunctionalCastExpr(
       hasType(IsStdString), hasDescendant(RedundantStringConstruction));
 
-  // Match method calls on std::string that modify or use the string, such as
-  // operator+, append(), substr(), etc.
-  // Exclude c_str()/data() as they are handled later.
-  const auto HasStringOperatorCall = hasDescendant(cxxOperatorCallExpr(
-      hasOverloadedOperatorName("+"), hasType(IsStdString)));
-  const auto HasStringMethodCall = hasDescendant(cxxMemberCallExpr(
-      on(hasType(IsStdString)), 
unless(callee(cxxMethodDecl(isCStrOrData())))));
-
-  const auto IsCallReturningString = callExpr(hasType(IsStdString));
-  const auto IsImplicitStringViewFromCall =
-      cxxConstructExpr(hasType(IsStdStringView),
-                       hasArgument(0, 
ignoringImplicit(IsCallReturningString)));
+  const auto RedundantTemporaryString =
+      expr(anyOf(RedundantStringConstruction, RedundantFunctionalCast));
 
   // Matches std::string(...).[c_str()|.data()]
-  const auto RedundantStringWithCStr = cxxMemberCallExpr(
-      callee(cxxMethodDecl(isCStrOrData())),
-      on(ignoringParenImpCasts(
-          anyOf(RedundantStringConstruction, RedundantFunctionalCast))));
-
-  // Main matcher: finds function calls where:
-  // 1. A parameter has type string_view
-  // 2. The corresponding argument contains a redundant std::string 
construction
-  //    (either functional cast syntax or direct construction/brace init)
-  // 3. The argument does NOT involve:
-  //    - String concatenation with operator+ (string_view doesn't support it)
-  //    - Method calls on the std::string (like append(), substr(), etc.)
+  const auto RedundantStringWithCStr =
+      cxxMemberCallExpr(callee(cxxMethodDecl(hasAnyName("c_str", "data"))),
+                        on(ignoringParenImpCasts(RedundantTemporaryString)));
+
+  // Main matcher: finds cases where an expression that's convertible to a
+  // std::string_view, instead of being used to construct the std::string_view
+  // directly, is first needlessly converted to a std::string.
----------------
localspook wrote:

That works :+1: 

https://github.com/llvm/llvm-project/pull/182783
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to