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()) {
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()) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits