[clang-tools-extra] [clang-tidy] performance-unnecessary-copy-initialization: Enhance the check for the scenario with MemberExpr initialization. (PR #151936)

Baranov Victor via cfe-commits cfe-commits at lists.llvm.org
Sat Aug 16 11:31:58 PDT 2025


================
@@ -273,6 +273,18 @@ void UnnecessaryCopyInitialization::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(LocalVarCopiedFrom(declRefExpr(
                          to(varDecl(hasLocalStorage()).bind(OldVarDeclId)))),
                      this);
+
+  auto DeclRefToConstVar =
+      declRefExpr(to(varDecl(anyOf(hasType(isConstQualified()),
+                                   hasType(references(isConstQualified()))))
+                         .bind(OldVarDeclId)));
+  Finder->addMatcher(
+      LocalVarCopiedFrom(
+          memberExpr(hasObjectExpression(anyOf(hasDescendant(DeclRefToConstVar),
----------------
vbvictor wrote:

Why do we need `hasDescendant`? It's an expensive operation and other matchers seems not to have it.

https://github.com/llvm/llvm-project/pull/151936


More information about the cfe-commits mailing list