Skip to content

Commit 0dc8fd7

Browse files
committed
[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 llvm-svn: 326799
1 parent 37c4d6d commit 0dc8fd7

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -295,16 +295,8 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
295295
}
296296
return false;
297297
};
298-
// Check the implicit conversion from the std::initializer_list type to
299-
// a class type.
300-
if (IsStdInitListInitConstructExpr(Arg))
298+
if (IsStdInitListInitConstructExpr(Arg->IgnoreImplicit()))
301299
return false;
302-
// The Arg can be a CXXBindTemporaryExpr, checking its underlying
303-
// construct expr.
304-
if (const auto * CTE = dyn_cast<CXXBindTemporaryExpr>(Arg)) {
305-
if (IsStdInitListInitConstructExpr(CTE->getSubExpr()))
306-
return false;
307-
}
308300
}
309301
}
310302
if (ArraySizeExpr.empty()) {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ struct G {
5050

5151
struct H {
5252
H(std::vector<int>);
53+
H(std::vector<int> &, double);
5354
H(MyVector<int>, int);
5455
};
5556

@@ -344,6 +345,13 @@ void initialization(int T, Base b) {
344345
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::make_unique instead
345346
// CHECK-FIXES: PH2.reset(new H({1, 2, 3}, 1));
346347

348+
std::unique_ptr<H> PH3 = std::unique_ptr<H>(new H({1, 2, 3}, 1.0));
349+
// CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead
350+
// CHECK-FIXES: std::unique_ptr<H> PH3 = std::unique_ptr<H>(new H({1, 2, 3}, 1.0));
351+
PH3.reset(new H({1, 2, 3}, 1.0));
352+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::make_unique instead
353+
// CHECK-FIXES: PH3.reset(new H({1, 2, 3}, 1.0));
354+
347355
std::unique_ptr<I> PI1 = std::unique_ptr<I>(new I(G({1, 2, 3})));
348356
// CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead
349357
// CHECK-FIXES: std::unique_ptr<I> PI1 = std::make_unique<I>(G({1, 2, 3}));

0 commit comments

Comments
 (0)