[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
Sat Nov 20 12:15:14 PST 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rGfefe20b99313: [clang-tidy] performance-unnecessary-copy-initialization: Correctly match theā€¦ (authored by flx).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114212/new/

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.388721.patch
Type: text/x-patch
Size: 1753 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211120/0fa77d16/attachment-0001.bin>


More information about the cfe-commits mailing list