[PATCH] D61642: [clang-tidy] Do not show incorrect fix in modernize-make-unique

Ilya Biryukov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 7 10:21:52 PDT 2019


ilya-biryukov updated this revision to Diff 198497.
ilya-biryukov marked 3 inline comments as done.
ilya-biryukov added a comment.

- Remove redundant check.
- Actually check the code stays the same in tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61642

Files:
  clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tools-extra/test/clang-tidy/modernize-make-unique.cpp


Index: clang-tools-extra/test/clang-tidy/modernize-make-unique.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/modernize-make-unique.cpp
+++ clang-tools-extra/test/clang-tidy/modernize-make-unique.cpp
@@ -273,6 +273,14 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use std::make_unique instead
   // CHECK-FIXES: std::make_unique<APair>(APair{T, 1});
 
+  // Check aggregate init with intermediate temporaries.
+  std::unique_ptr<APair> PAggrTemp = std::unique_ptr<APair>(new APair({T, 1}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:38: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr<APair> PAggrTemp = std::unique_ptr<APair>(new APair({T, 1}));
+  PAggrTemp.reset(new APair({T, 1}));
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use std::make_unique instead
+  // CHECK-FIXES: PAggrTemp.reset(new APair({T, 1}));
+
   // Test different kinds of initialization of the pointee, when the unique_ptr
   // is initialized with braces.
 
Index: clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -292,12 +292,13 @@
   //   Foo{1} => false
   auto HasListIntializedArgument = [](const CXXConstructExpr *CE) {
     for (const auto *Arg : CE->arguments()) {
+      Arg = Arg->IgnoreImplicit();
+
       if (isa<CXXStdInitializerListExpr>(Arg) || isa<InitListExpr>(Arg))
         return true;
       // Check whether we implicitly construct a class from a
       // std::initializer_list.
-      if (const auto *ImplicitCE =
-              dyn_cast<CXXConstructExpr>(Arg->IgnoreImplicit())) {
+      if (const auto *ImplicitCE = dyn_cast<CXXConstructExpr>(Arg)) {
         if (ImplicitCE->isStdInitListInitialization())
           return true;
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61642.198497.patch
Type: text/x-patch
Size: 1944 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190507/8f7461d0/attachment.bin>


More information about the cfe-commits mailing list