[clang-tools-extra] fefe20b - [clang-tidy] performance-unnecessary-copy-initialization: Correctly match the type name of the thisPointertype.
Felix Berger via cfe-commits
cfe-commits at lists.llvm.org
Sat Nov 20 12:15:12 PST 2021
Author: Felix Berger
Date: 2021-11-20T15:13:41-05:00
New Revision: fefe20b99313d6b0738806d1504652c3b7edb9e0
URL: https://github.com/llvm/llvm-project/commit/fefe20b99313d6b0738806d1504652c3b7edb9e0
DIFF: https://github.com/llvm/llvm-project/commit/fefe20b99313d6b0738806d1504652c3b7edb9e0.diff
LOG: [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
Added:
Modified:
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization-excluded-container-types.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
index 2cdd7827ee42..514ce6f6e3b8 100644
--- a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
+++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
@@ -87,11 +87,9 @@ AST_MATCHER_FUNCTION_P(StatementMatcher, isConstRefReturningMethodCall,
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
index 6d1d28ad1498..88b850fe2ff8 100644
--- 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 @@ void excludedConstIncorrectType() {
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();
+}
More information about the cfe-commits
mailing list