Index: clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryCopyInitialization.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryCopyInitialization.cpp +++ clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryCopyInitialization.cpp @@ -19,7 +19,6 @@ using namespace ::clang::ast_matchers; namespace { -AST_MATCHER(VarDecl, isLocalVarDecl) { return Node.isLocalVarDecl(); } AST_MATCHER(QualType, isPointerType) { return Node->isPointerType(); } } // namespace @@ -43,7 +42,7 @@ unless(callee(cxxMethodDecl()))); Finder->addMatcher( varDecl( - isLocalVarDecl(), hasType(isConstQualified()), + hasLocalStorage(), hasType(isConstQualified()), hasType(matchers::isExpensiveToCopy()), hasInitializer(cxxConstructExpr( hasDeclaration(cxxConstructorDecl(isCopyConstructor())), Index: clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-copy-initialization.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-copy-initialization.cpp +++ clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-copy-initialization.cpp @@ -110,6 +110,10 @@ const TrivialToCopyType VarCopyConstructed(TrivialTypeReference()); } +void NegativeStaticLocalVar(const ExpensiveToCopyType &Obj) { + static const auto StaticVar = Obj.reference(); +} + void NegativeFunctionCallExpensiveTypeNonConstVariable() { auto AutoAssigned = ExpensiveTypeReference(); auto AutoCopyConstructed(ExpensiveTypeReference());