Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp =================================================================== --- clang-tidy/modernize/MakeSmartPtrCheck.cpp +++ clang-tidy/modernize/MakeSmartPtrCheck.cpp @@ -262,20 +262,24 @@ break; } case CXXNewExpr::CallInit: { - // FIXME: Add fixes for constructors with initializer-list parameters. + // FIXME: Add fixes for constructors with parameters that can be created + // with a C++11 braced-init-list (e.g. std::vector, std::map). // Unlike ordinal cases, braced list can not be deduced in // std::make_smart_ptr, we need to specify the type explicitly in the fixes: // struct S { S(std::initializer_list, int); }; + // struct S2 { S2(std::vector); }; // smart_ptr(new S({1, 2, 3}, 1)); // C++98 call-style initialization // smart_ptr(new S({}, 1)); + // smart_ptr(new S2({1, 2, 3})); // The above samples have to be replaced with: // std::make_smart_ptr(std::initializer_list({1, 2, 3}), 1); // std::make_smart_ptr(std::initializer_list({}), 1); + // std::make_smart_ptr(std::vector({1, 2, 3})); if (const auto *CE = New->getConstructExpr()) { - for (const auto *Arg : CE->arguments()) { - if (llvm::isa(Arg)) { - return false; - } + if (!ast_matchers::match(findAll(cxxStdInitializerListExpr()), *CE, + CE->getConstructor()->getASTContext()) + .empty()) { + return false; } } if (ArraySizeExpr.empty()) { Index: test/clang-tidy/Inputs/modernize-smart-ptr/initializer_list.h =================================================================== --- test/clang-tidy/Inputs/modernize-smart-ptr/initializer_list.h +++ test/clang-tidy/Inputs/modernize-smart-ptr/initializer_list.h @@ -22,4 +22,10 @@ const _E *begin() const { return __begin_; } const _E *end() const { return __begin_ + __size_; } }; + +template +class vector { + public: + vector(initializer_list<_E> init); +}; } // namespace std Index: test/clang-tidy/modernize-make-unique.cpp =================================================================== --- test/clang-tidy/modernize-make-unique.cpp +++ test/clang-tidy/modernize-make-unique.cpp @@ -43,6 +43,10 @@ G(int); }; +struct H { + H(std::vector); +}; + namespace { class Foo {}; } // namespace @@ -316,6 +320,13 @@ // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead // CHECK-FIXES: std::unique_ptr PG3 = std::unique_ptr(new G{1, 2}); + std::unique_ptr PH1 = std::unique_ptr(new H({1, 2, 3})); + // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead + // CHECK-FIXES: std::unique_ptr PH1 = std::unique_ptr(new H({1, 2, 3})); + PH1.reset(new H({1, 2, 3})); + // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::make_unique instead + // CHECK-FIXES: PH1.reset(new H({1, 2, 3})); + std::unique_ptr FF = std::unique_ptr(new Foo()); // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: // CHECK-FIXES: std::unique_ptr FF = std::make_unique();