corona10 updated this revision to Diff 455544.
corona10 added a comment.

Add unittest


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

https://reviews.llvm.org/D132640

Files:
  clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp
@@ -1061,6 +1061,44 @@
   // CHECK-FIXES: priority_queue.emplace(13);
 }
 
+void test_Alias() {
+  typedef std::list<Foo> L;
+  using DQ = std::deque<Foo>;
+  L l;
+  l.push_back(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back instead of 
push_back [modernize-use-emplace]
+  // CHECK-FIXES: l.emplace_back(3);
+
+  DQ dq;
+  dq.push_back(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back instead of 
push_back [modernize-use-emplace]
+  // CHECK-FIXES: dq.emplace_back(3);
+
+  typedef std::stack<Foo> STACK;
+  using PQ = std::priority_queue<Foo>;
+  STACK stack;
+  stack.push(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use emplace instead of push 
[modernize-use-emplace]
+  // CHECK-FIXES: stack.emplace(3);
+
+  PQ pq;
+  pq.push(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace instead of push 
[modernize-use-emplace]
+  // CHECK-FIXES: pq.emplace(3);
+
+  typedef std::forward_list<Foo> FL;
+  using DQ2 = std::deque<Foo>;
+  FL fl;
+  fl.push_front(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_front instead of 
push_front [modernize-use-emplace]
+  // CHECK-FIXES: fl.emplace_front(3);
+
+  DQ2 dq2;
+  dq2.push_front(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use emplace_front instead of 
push_front [modernize-use-emplace]
+  // CHECK-FIXES: dq2.emplace_front(3);
+}
+
 struct Bar {
 public:
   Bar(){};
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
@@ -132,17 +132,20 @@
   // because this requires special treatment (it could cause performance
   // regression)
   // + match for emplace calls that should be replaced with insertion
-  auto CallPushBack = cxxMemberCallExpr(
-      hasDeclaration(functionDecl(hasName("push_back"))),
-      on(hasType(cxxRecordDecl(hasAnyName(ContainersWithPushBack)))));
-
-  auto CallPush = cxxMemberCallExpr(
-      hasDeclaration(functionDecl(hasName("push"))),
-      on(hasType(cxxRecordDecl(hasAnyName(ContainersWithPush)))));
-
-  auto CallPushFront = cxxMemberCallExpr(
-      hasDeclaration(functionDecl(hasName("push_front"))),
-      on(hasType(cxxRecordDecl(hasAnyName(ContainersWithPushFront)))));
+  auto CallPushBack =
+      cxxMemberCallExpr(hasDeclaration(functionDecl(hasName("push_back"))),
+                        on(hasType(hasCanonicalType(hasDeclaration(
+                            namedDecl(hasAnyName(ContainersWithPushBack)))))));
+
+  auto CallPush =
+      cxxMemberCallExpr(hasDeclaration(functionDecl(hasName("push"))),
+                        on(hasType(hasCanonicalType(hasDeclaration(
+                            namedDecl(hasAnyName(ContainersWithPush)))))));
+
+  auto CallPushFront =
+      cxxMemberCallExpr(hasDeclaration(functionDecl(hasName("push_front"))),
+                        on(hasType(hasCanonicalType(hasDeclaration(
+                            
namedDecl(hasAnyName(ContainersWithPushFront)))))));
 
   auto CallEmplacy = cxxMemberCallExpr(
       hasDeclaration(


Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp
@@ -1061,6 +1061,44 @@
   // CHECK-FIXES: priority_queue.emplace(13);
 }
 
+void test_Alias() {
+  typedef std::list<Foo> L;
+  using DQ = std::deque<Foo>;
+  L l;
+  l.push_back(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back instead of push_back [modernize-use-emplace]
+  // CHECK-FIXES: l.emplace_back(3);
+
+  DQ dq;
+  dq.push_back(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back instead of push_back [modernize-use-emplace]
+  // CHECK-FIXES: dq.emplace_back(3);
+
+  typedef std::stack<Foo> STACK;
+  using PQ = std::priority_queue<Foo>;
+  STACK stack;
+  stack.push(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use emplace instead of push [modernize-use-emplace]
+  // CHECK-FIXES: stack.emplace(3);
+
+  PQ pq;
+  pq.push(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace instead of push [modernize-use-emplace]
+  // CHECK-FIXES: pq.emplace(3);
+
+  typedef std::forward_list<Foo> FL;
+  using DQ2 = std::deque<Foo>;
+  FL fl;
+  fl.push_front(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_front instead of push_front [modernize-use-emplace]
+  // CHECK-FIXES: fl.emplace_front(3);
+
+  DQ2 dq2;
+  dq2.push_front(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use emplace_front instead of push_front [modernize-use-emplace]
+  // CHECK-FIXES: dq2.emplace_front(3);
+}
+
 struct Bar {
 public:
   Bar(){};
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
@@ -132,17 +132,20 @@
   // because this requires special treatment (it could cause performance
   // regression)
   // + match for emplace calls that should be replaced with insertion
-  auto CallPushBack = cxxMemberCallExpr(
-      hasDeclaration(functionDecl(hasName("push_back"))),
-      on(hasType(cxxRecordDecl(hasAnyName(ContainersWithPushBack)))));
-
-  auto CallPush = cxxMemberCallExpr(
-      hasDeclaration(functionDecl(hasName("push"))),
-      on(hasType(cxxRecordDecl(hasAnyName(ContainersWithPush)))));
-
-  auto CallPushFront = cxxMemberCallExpr(
-      hasDeclaration(functionDecl(hasName("push_front"))),
-      on(hasType(cxxRecordDecl(hasAnyName(ContainersWithPushFront)))));
+  auto CallPushBack =
+      cxxMemberCallExpr(hasDeclaration(functionDecl(hasName("push_back"))),
+                        on(hasType(hasCanonicalType(hasDeclaration(
+                            namedDecl(hasAnyName(ContainersWithPushBack)))))));
+
+  auto CallPush =
+      cxxMemberCallExpr(hasDeclaration(functionDecl(hasName("push"))),
+                        on(hasType(hasCanonicalType(hasDeclaration(
+                            namedDecl(hasAnyName(ContainersWithPush)))))));
+
+  auto CallPushFront =
+      cxxMemberCallExpr(hasDeclaration(functionDecl(hasName("push_front"))),
+                        on(hasType(hasCanonicalType(hasDeclaration(
+                            namedDecl(hasAnyName(ContainersWithPushFront)))))));
 
   auto CallEmplacy = cxxMemberCallExpr(
       hasDeclaration(
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to