[PATCH] D114212: [clang-tidy] performance-unnecessary-copy-initialization: Correctly match the type name of the thisPointertype.

Felix Berger via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 18 17:37:17 PST 2021


flx created this revision.
flx added reviewers: ymandel, courbet, aaron.ballman.
Herald added subscribers: carlosgalvezp, xazax.hun.
flx requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

The matching did not work correctly for pointer and reference types.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114212

Files:
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
  clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization-excluded-container-types.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization-excluded-container-types.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization-excluded-container-types.cpp
+++ 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();
+}
Index: clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
===================================================================
--- clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
+++ 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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114212.388359.patch
Type: text/x-patch
Size: 1753 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211119/b9f2b5d5/attachment-0001.bin>


More information about the cfe-commits mailing list