[PATCH] D132640: [clang-tidy] Fix modernize-use-emplace to support alias cases

Dong-hee Na via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 25 02:37:27 PDT 2022


corona10 created this revision.
Herald added subscribers: carlosgalvezp, jeroen.dobbelaere, xazax.hun.
Herald added a project: All.
corona10 requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Fix modernize-use-emplace to support alias cases


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132640

Files:
  clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp


Index: clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
@@ -134,15 +134,21 @@
   // + match for emplace calls that should be replaced with insertion
   auto CallPushBack = cxxMemberCallExpr(
       hasDeclaration(functionDecl(hasName("push_back"))),
-      on(hasType(cxxRecordDecl(hasAnyName(ContainersWithPushBack)))));
+      on(anyOf(hasType(cxxRecordDecl(hasAnyName(ContainersWithPushBack))),
+               hasType(hasCanonicalType(hasDeclaration(
+                   namedDecl(hasAnyName(ContainersWithPushBack))))))));
 
   auto CallPush = cxxMemberCallExpr(
       hasDeclaration(functionDecl(hasName("push"))),
-      on(hasType(cxxRecordDecl(hasAnyName(ContainersWithPush)))));
+      on(anyOf(hasType(cxxRecordDecl(hasAnyName(ContainersWithPush))),
+               hasType(hasCanonicalType(hasDeclaration(
+                   namedDecl(hasAnyName(ContainersWithPush))))))));
 
   auto CallPushFront = cxxMemberCallExpr(
       hasDeclaration(functionDecl(hasName("push_front"))),
-      on(hasType(cxxRecordDecl(hasAnyName(ContainersWithPushFront)))));
+      on(anyOf(hasType(cxxRecordDecl(hasAnyName(ContainersWithPushFront))),
+               hasType(hasCanonicalType(hasDeclaration(
+                   namedDecl(hasAnyName(ContainersWithPushFront))))))));
 
   auto CallEmplacy = cxxMemberCallExpr(
       hasDeclaration(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132640.455515.patch
Type: text/x-patch
Size: 1544 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220825/c0e73a6c/attachment.bin>


More information about the cfe-commits mailing list