[PATCH] D44137: [clang-tidy] Fix one corner case in make-unique check.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 6 01:40:38 PST 2018
hokein created this revision.
hokein added a reviewer: ilya-biryukov.
Herald added subscribers: xazax.hun, klimek.
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.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D44137
Files:
clang-tidy/modernize/MakeSmartPtrCheck.cpp
test/clang-tidy/modernize-make-unique.cpp
Index: test/clang-tidy/modernize-make-unique.cpp
===================================================================
--- test/clang-tidy/modernize-make-unique.cpp
+++ test/clang-tidy/modernize-make-unique.cpp
@@ -50,6 +50,7 @@
struct H {
H(std::vector<int>);
+ H(std::vector<int> &, double);
H(MyVector<int>, int);
};
@@ -344,6 +345,13 @@
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::make_unique instead
// CHECK-FIXES: PH2.reset(new H({1, 2, 3}, 1));
+ std::unique_ptr<H> PH3 = std::unique_ptr<H>(new H({1, 2, 3}, 1.0));
+ // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead
+ // CHECK-FIXES: std::unique_ptr<H> PH3 = std::unique_ptr<H>(new H({1, 2, 3}, 1.0));
+ PH3.reset(new H({1, 2, 3}, 1.0));
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::make_unique instead
+ // CHECK-FIXES: PH3.reset(new H({1, 2, 3}, 1.0));
+
std::unique_ptr<I> PI1 = std::unique_ptr<I>(new I(G({1, 2, 3})));
// CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead
// CHECK-FIXES: std::unique_ptr<I> PI1 = std::make_unique<I>(G({1, 2, 3}));
Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp
===================================================================
--- clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -295,16 +295,8 @@
}
return false;
};
- // Check the implicit conversion from the std::initializer_list type to
- // a class type.
- if (IsStdInitListInitConstructExpr(Arg))
+ if (IsStdInitListInitConstructExpr(Arg->IgnoreImplicit()))
return false;
- // The Arg can be a CXXBindTemporaryExpr, checking its underlying
- // construct expr.
- if (const auto * CTE = dyn_cast<CXXBindTemporaryExpr>(Arg)) {
- if (IsStdInitListInitConstructExpr(CTE->getSubExpr()))
- return false;
- }
}
}
if (ArraySizeExpr.empty()) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44137.137136.patch
Type: text/x-patch
Size: 1970 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180306/98b47a5b/attachment-0001.bin>
More information about the cfe-commits
mailing list