Index: clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp +++ clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp @@ -281,12 +281,25 @@ if (isa(Arg)) { return false; } + // Check whether we construct a class from a std::initializer_list. + // If so, we won't generate the fixes. + auto IsStdInitListInitConstructExpr = [](const Expr* E) { + assert(E); + if (const auto *ImplicitCE = dyn_cast(E)) { + if (ImplicitCE->isStdInitListInitialization()) + return true; + } + return false; + }; // Check the implicit conversion from the std::initializer_list type to // a class type. - if (const auto *ImplicitCE = dyn_cast(Arg)) { - if (ImplicitCE->isStdInitListInitialization()) { + if (IsStdInitListInitConstructExpr(Arg)) + return false; + // The Arg can be a CXXBindTemporaryExpr, checking its underlying + // construct expr. + if (const auto * CTE = dyn_cast(Arg)) { + if (IsStdInitListInitConstructExpr(CTE->getSubExpr())) return false; - } } } } Index: clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-smart-ptr/initializer_list.h =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-smart-ptr/initializer_list.h +++ clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-smart-ptr/initializer_list.h @@ -27,5 +27,6 @@ class vector { public: vector(initializer_list<_E> init); + ~vector(); }; } // namespace std Index: clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp +++ clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp @@ -25,6 +25,11 @@ int a, b; }; +template +struct MyVector { + MyVector(std::initializer_list); +}; + struct Empty {}; struct E { @@ -45,6 +50,7 @@ struct H { H(std::vector); + H(MyVector, int); }; struct I { @@ -331,6 +337,13 @@ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::make_unique instead // CHECK-FIXES: PH1.reset(new H({1, 2, 3})); + std::unique_ptr PH2 = std::unique_ptr(new H({1, 2, 3}, 1)); + // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead + // CHECK-FIXES: std::unique_ptr PH2 = std::unique_ptr(new H({1, 2, 3}, 1)); + PH2.reset(new H({1, 2, 3}, 1)); + // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::make_unique instead + // CHECK-FIXES: PH2.reset(new H({1, 2, 3}, 1)); + std::unique_ptr PI1 = std::unique_ptr(new I(G({1, 2, 3}))); // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead // CHECK-FIXES: std::unique_ptr PI1 = std::make_unique(G({1, 2, 3}));