[clang-tools-extra] r252041 - Improve modernize-make-unique matcher.

Angel Garcia Gomez via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 4 02:27:51 PST 2015


Author: angelgarcia
Date: Wed Nov  4 04:27:51 2015
New Revision: 252041

URL: http://llvm.org/viewvc/llvm-project?rev=252041&view=rev
Log:
Improve modernize-make-unique matcher.

Summary: "std::unique_ptr<int>" is not the same type as "std::unique_ptr<int, std::default_delete<int>>", unless we insert a "hasCanonicalType" in the middle. Probably it also happens in other cases related to default template argument.

Reviewers: klimek

Subscribers: alexfh, cfe-commits

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

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=252041&r1=252040&r2=252041&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/MakeUniqueCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/MakeUniqueCheck.cpp Wed Nov  4 04:27:51 2015
@@ -42,9 +42,10 @@ void MakeUniqueCheck::registerMatchers(M
                                               qualType(equalsBoundNode(
                                                   PointerType))))))))))))))),
                 argumentCountIs(1),
-                hasArgument(0, cxxNewExpr(hasType(pointsTo(qualType(
-                                              equalsBoundNode(PointerType)))))
-                                   .bind(NewExpression)))
+                hasArgument(
+                    0, cxxNewExpr(hasType(pointsTo(qualType(hasCanonicalType(
+                                      equalsBoundNode(PointerType))))))
+                           .bind(NewExpression)))
                 .bind(ConstructorCall))),
         this);
   }

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=252041&r1=252040&r2=252041&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 Wed Nov  4 04:27:51 2015
@@ -195,3 +195,9 @@ void whitespaces() {
   // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use std::make_unique instead
   // CHECK-FIXES: auto Spaces = std::make_unique<int>();
 }
+
+void nesting() {
+  auto Nest = std::unique_ptr<std::unique_ptr<int>>(new std::unique_ptr<int>(new int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: use std::make_unique instead
+  // CHECK-FIXES: auto Nest = std::make_unique<std::unique_ptr<int>>(new int);
+}




More information about the cfe-commits mailing list