diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp --- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp @@ -298,11 +298,20 @@ return true; // Check whether we implicitly construct a class from a // std::initializer_list. - if (const auto *ImplicitCE = dyn_cast(Arg)) { - if (ImplicitCE->isStdInitListInitialization()) + if (const auto *CEArg = dyn_cast(Arg)) { + // Strip the ediable move constructor, it is presented in C++11/14 mode. + // e.g. Foo(Bar{1, 2}), the Bar init-list constructor is wrapped around + // an elidable move constructor. + if (CEArg->isElidable()) { + if (const auto *TempExp = CEArg->getArg(0)) { + if (const auto *UnwrappedCE = + dyn_cast(TempExp->IgnoreImplicit())) + CEArg = UnwrappedCE; + } + } + if (CEArg->isStdInitListInitialization()) return true; } - return false; } return false; }; diff --git a/clang-tools-extra/test/clang-tidy/modernize-make-unique.cpp b/clang-tools-extra/test/clang-tidy/modernize-make-unique.cpp --- a/clang-tools-extra/test/clang-tidy/modernize-make-unique.cpp +++ b/clang-tools-extra/test/clang-tidy/modernize-make-unique.cpp @@ -1,5 +1,4 @@ -// RUN: %check_clang_tidy -std=c++14 %s modernize-make-unique %t -- -- -I %S/Inputs/modernize-smart-ptr -// FIXME: Fix the checker to work in C++17 mode. +// RUN: %check_clang_tidy -std=c++14,c++17 %s modernize-make-unique %t -- -- -I %S/Inputs/modernize-smart-ptr #include "unique_ptr.h" #include "initializer_list.h" @@ -455,10 +454,10 @@ std::unique_ptr PJ2 = std::unique_ptr(new J(E{1, 2}, 1)); // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead - // CHECK-FIXES: std::unique_ptr PJ2 = std::make_unique(E{1, 2}, 1); + // CHECK-FIXES: std::unique_ptr PJ2 = std::unique_ptr(new J(E{1, 2}, 1)); PJ2.reset(new J(E{1, 2}, 1)); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::make_unique instead - // CHECK-FIXES: PJ2 = std::make_unique(E{1, 2}, 1); + // CHECK-FIXES: PJ2.reset(new J(E{1, 2}, 1)); std::unique_ptr PJ3 = std::unique_ptr(new J{ {1, 2}, 1 }); // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead @@ -469,10 +468,10 @@ std::unique_ptr PJ4 = std::unique_ptr(new J{E{1, 2}, 1}); // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead - // CHECK-FIXES: std::unique_ptr PJ4 = std::make_unique(E{1, 2}, 1); + // CHECK-FIXES: std::unique_ptr PJ4 = std::unique_ptr(new J{E{1, 2}, 1}); PJ4.reset(new J{E{1, 2}, 1}); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::make_unique instead - // CHECK-FIXES: PJ4 = std::make_unique(E{1, 2}, 1); + // CHECK-FIXES: PJ4.reset(new J{E{1, 2}, 1}); std::unique_ptr FF = std::unique_ptr(new Foo()); // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: