[clang-tools-extra] r326799 - [clang-tidy] Fix one corner case in make-unique check.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 6 06:34:35 PST 2018


Author: hokein
Date: Tue Mar  6 06:34:35 2018
New Revision: 326799

URL: http://llvm.org/viewvc/llvm-project?rev=326799&view=rev
Log:
[clang-tidy] Fix one corner case in make-unique check.

Summary:
Previously, we tried to cover all "std::initializer_list" implicit conversion
cases in the code, but there are some corner cases that not covered (see
newly-added test in the patch).

Sipping all implicit AST nodes is a better way to filter out all these cases.

Reviewers: ilya-biryukov

Subscribers: klimek, xazax.hun, cfe-commits

Differential Revision: https://reviews.llvm.org/D44137

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

Modified: clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp?rev=326799&r1=326798&r2=326799&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp Tue Mar  6 06:34:35 2018
@@ -295,16 +295,8 @@ bool MakeSmartPtrCheck::replaceNew(Diagn
           }
           return false;
         };
-        // Check the implicit conversion from the std::initializer_list type to
-        // a class type.
-        if (IsStdInitListInitConstructExpr(Arg))
+        if (IsStdInitListInitConstructExpr(Arg->IgnoreImplicit()))
           return false;
-        // The Arg can be a CXXBindTemporaryExpr, checking its underlying
-        // construct expr.
-        if (const auto * CTE = dyn_cast<CXXBindTemporaryExpr>(Arg)) {
-          if (IsStdInitListInitConstructExpr(CTE->getSubExpr()))
-            return false;
-        }
       }
     }
     if (ArraySizeExpr.empty()) {

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=326799&r1=326798&r2=326799&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 Tue Mar  6 06:34:35 2018
@@ -50,6 +50,7 @@ struct G {
 
 struct H {
   H(std::vector<int>);
+  H(std::vector<int> &, double);
   H(MyVector<int>, int);
 };
 
@@ -344,6 +345,13 @@ void initialization(int T, Base b) {
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::make_unique instead
   // CHECK-FIXES: PH2.reset(new H({1, 2, 3}, 1));
 
+  std::unique_ptr<H> PH3 = std::unique_ptr<H>(new H({1, 2, 3}, 1.0));
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr<H> PH3 = std::unique_ptr<H>(new H({1, 2, 3}, 1.0));
+  PH3.reset(new H({1, 2, 3}, 1.0));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::make_unique instead
+  // CHECK-FIXES: PH3.reset(new H({1, 2, 3}, 1.0));
+
   std::unique_ptr<I> PI1 = std::unique_ptr<I>(new I(G({1, 2, 3})));
   // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead
   // CHECK-FIXES: std::unique_ptr<I> PI1 = std::make_unique<I>(G({1, 2, 3}));




More information about the cfe-commits mailing list