diff --git a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp --- a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp +++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp @@ -87,11 +87,9 @@ callee(cxxMethodDecl( returns(hasCanonicalType(matchers::isReferenceToConst()))) .bind(MethodDeclId)), - on(declRefExpr(to( - varDecl( - unless(hasType(qualType(hasCanonicalType(hasDeclaration(namedDecl( - matchers::matchesAnyListedName(ExcludedContainerTypes)))))))) - .bind(ObjectArgId))))); + on(declRefExpr(to(varDecl().bind(ObjectArgId)))), + thisPointerType(namedDecl( + unless(matchers::matchesAnyListedName(ExcludedContainerTypes))))); } AST_MATCHER_FUNCTION(StatementMatcher, isConstRefReturningFunctionCall) { diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization-excluded-container-types.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization-excluded-container-types.cpp --- a/clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization-excluded-container-types.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization-excluded-container-types.cpp @@ -58,3 +58,13 @@ const auto E = C.secretlyMutates(); E.constMethod(); } + +void excludedConstIncorrectTypeAsPointer(ConstInCorrectType *C) { + const auto E = C->secretlyMutates(); + E.constMethod(); +} + +void excludedConstIncorrectTypeAsReference(const ConstInCorrectType &C) { + const auto E = C.secretlyMutates(); + E.constMethod(); +}