[clang-tools-extra] r249305 - Use better mocks in modernize-make-unique, and fix matcher.

Angel Garcia Gomez via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 5 05:20:17 PDT 2015


Author: angelgarcia
Date: Mon Oct  5 07:20:17 2015
New Revision: 249305

URL: http://llvm.org/viewvc/llvm-project?rev=249305&view=rev
Log:
Use better mocks in modernize-make-unique, and fix matcher.

Summary: 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.

Reviewers: klimek

Subscribers: alexfh, cfe-commits

Differential Revision: http://reviews.llvm.org/D13433

Modified:
    clang-tools-extra/trunk/clang-tidy/modernize/MakeUniqueCheck.cpp
    clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/MakeUniqueCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/MakeUniqueCheck.cpp?rev=249305&r1=249304&r2=249305&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/MakeUniqueCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/MakeUniqueCheck.cpp Mon Oct  5 07:20:17 2015
@@ -29,10 +29,18 @@ void MakeUniqueCheck::registerMatchers(M
             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)))))

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp?rev=249305&r1=249304&r2=249305&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp Mon Oct  5 07:20:17 2015
@@ -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);




More information about the cfe-commits mailing list