angelgarcia created this revision.
angelgarcia added a reviewer: klimek.
angelgarcia added subscribers: cfe-commits, alexfh.

Add the second template argument to the unique_ptr mock, and update the matcher 
so that it only matches against cases where the second argument is the default.

http://reviews.llvm.org/D13433

Files:
  clang-tidy/modernize/MakeUniqueCheck.cpp
  test/clang-tidy/modernize-make-unique.cpp

Index: test/clang-tidy/modernize-make-unique.cpp
===================================================================
--- test/clang-tidy/modernize-make-unique.cpp
+++ test/clang-tidy/modernize-make-unique.cpp
@@ -2,7 +2,10 @@
 
 namespace std {
 
-template <typename type>
+template <typename T>
+class default_delete {};
+
+template <typename type, typename Deleter = std::default_delete<type>>
 class unique_ptr {
 public:
   unique_ptr(type *ptr);
Index: clang-tidy/modernize/MakeUniqueCheck.cpp
===================================================================
--- clang-tidy/modernize/MakeUniqueCheck.cpp
+++ clang-tidy/modernize/MakeUniqueCheck.cpp
@@ -29,10 +29,18 @@
             cxxConstructExpr(
                 
hasType(qualType(hasDeclaration(classTemplateSpecializationDecl(
                     matchesName("::std::unique_ptr"),
-                    templateArgumentCountIs(1),
+                    templateArgumentCountIs(2),
+                    hasTemplateArgument(0, templateArgument(refersToType(
+                                               qualType().bind(PointerType)))),
                     hasTemplateArgument(
-                        0, templateArgument(
-                               
refersToType(qualType().bind(PointerType)))))))),
+                        1, templateArgument(refersToType(qualType(
+                               hasDeclaration(classTemplateSpecializationDecl(
+                                   matchesName("::std::default_delete"),
+                                   templateArgumentCountIs(1),
+                                   hasTemplateArgument(
+                                       0, templateArgument(refersToType(
+                                              qualType(equalsBoundNode(
+                                                  PointerType))))))))))))))),
                 argumentCountIs(1),
                 hasArgument(0, cxxNewExpr(hasType(pointsTo(qualType(
                                               equalsBoundNode(PointerType)))))


Index: test/clang-tidy/modernize-make-unique.cpp
===================================================================
--- test/clang-tidy/modernize-make-unique.cpp
+++ test/clang-tidy/modernize-make-unique.cpp
@@ -2,7 +2,10 @@
 
 namespace std {
 
-template <typename type>
+template <typename T>
+class default_delete {};
+
+template <typename type, typename Deleter = std::default_delete<type>>
 class unique_ptr {
 public:
   unique_ptr(type *ptr);
Index: clang-tidy/modernize/MakeUniqueCheck.cpp
===================================================================
--- clang-tidy/modernize/MakeUniqueCheck.cpp
+++ clang-tidy/modernize/MakeUniqueCheck.cpp
@@ -29,10 +29,18 @@
             cxxConstructExpr(
                 hasType(qualType(hasDeclaration(classTemplateSpecializationDecl(
                     matchesName("::std::unique_ptr"),
-                    templateArgumentCountIs(1),
+                    templateArgumentCountIs(2),
+                    hasTemplateArgument(0, templateArgument(refersToType(
+                                               qualType().bind(PointerType)))),
                     hasTemplateArgument(
-                        0, templateArgument(
-                               refersToType(qualType().bind(PointerType)))))))),
+                        1, templateArgument(refersToType(qualType(
+                               hasDeclaration(classTemplateSpecializationDecl(
+                                   matchesName("::std::default_delete"),
+                                   templateArgumentCountIs(1),
+                                   hasTemplateArgument(
+                                       0, templateArgument(refersToType(
+                                              qualType(equalsBoundNode(
+                                                  PointerType))))))))))))))),
                 argumentCountIs(1),
                 hasArgument(0, cxxNewExpr(hasType(pointsTo(qualType(
                                               equalsBoundNode(PointerType)))))
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to