Skip to content

Commit 4c32d4f

Browse files
committedMay 8, 2019
[clang-tidy] Do not show incorrect fix in modernize-make-unique
Summary: The case when initialize_list hides behind an implicit case was not handled before. Reviewers: aaron.ballman Reviewed By: aaron.ballman Subscribers: xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D61642 llvm-svn: 360231
1 parent e96c98f commit 4c32d4f

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed
 

‎clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,13 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
292292
// Foo{1} => false
293293
auto HasListIntializedArgument = [](const CXXConstructExpr *CE) {
294294
for (const auto *Arg : CE->arguments()) {
295+
Arg = Arg->IgnoreImplicit();
296+
295297
if (isa<CXXStdInitializerListExpr>(Arg) || isa<InitListExpr>(Arg))
296298
return true;
297299
// Check whether we implicitly construct a class from a
298300
// std::initializer_list.
299-
if (const auto *ImplicitCE =
300-
dyn_cast<CXXConstructExpr>(Arg->IgnoreImplicit())) {
301+
if (const auto *ImplicitCE = dyn_cast<CXXConstructExpr>(Arg)) {
301302
if (ImplicitCE->isStdInitListInitialization())
302303
return true;
303304
}

‎clang-tools-extra/test/clang-tidy/modernize-make-unique.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,14 @@ void initialization(int T, Base b) {
273273
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use std::make_unique instead
274274
// CHECK-FIXES: std::make_unique<APair>(APair{T, 1});
275275

276+
// Check aggregate init with intermediate temporaries.
277+
std::unique_ptr<APair> PAggrTemp = std::unique_ptr<APair>(new APair({T, 1}));
278+
// CHECK-MESSAGES: :[[@LINE-1]]:38: warning: use std::make_unique instead
279+
// CHECK-FIXES: std::unique_ptr<APair> PAggrTemp = std::unique_ptr<APair>(new APair({T, 1}));
280+
PAggrTemp.reset(new APair({T, 1}));
281+
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use std::make_unique instead
282+
// CHECK-FIXES: PAggrTemp.reset(new APair({T, 1}));
283+
276284
// Test different kinds of initialization of the pointee, when the unique_ptr
277285
// is initialized with braces.
278286

0 commit comments

Comments
 (0)