[clang-tidy] performance-unnecessary-copy-initialization: Correctly match the type name of the thisPointertype.
The matching did not work correctly for pointer and reference types.
Differential Revision: https://reviews.llvm.org/D114212
Reviewed-by: courbet
GitOrigin-RevId: fefe20b99313d6b0738806d1504652c3b7edb9e0
diff --git a/clang-tidy/performance/UnnecessaryCopyInitialization.cpp b/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
index 2cdd782..514ce6f 100644
--- a/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
+++ b/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/test/clang-tidy/checkers/performance-unnecessary-copy-initialization-excluded-container-types.cpp b/test/clang-tidy/checkers/performance-unnecessary-copy-initialization-excluded-container-types.cpp
index 6d1d28a..88b850f 100644
--- a/test/clang-tidy/checkers/performance-unnecessary-copy-initialization-excluded-container-types.cpp
+++ b/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();
+}