[clang-tools-extra] r360231 - [clang-tidy] Do not show incorrect fix in modernize-make-unique
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Wed May 8 01:52:18 PDT 2019
Author: ibiryukov
Date: Wed May 8 01:52:18 2019
New Revision: 360231
URL: http://llvm.org/viewvc/llvm-project?rev=360231&view=rev
Log:
[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
Modified:
clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp
Modified: clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp?rev=360231&r1=360230&r2=360231&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp Wed May 8 01:52:18 2019
@@ -292,12 +292,13 @@ bool MakeSmartPtrCheck::replaceNew(Diagn
// Foo{1} => false
auto HasListIntializedArgument = [](const CXXConstructExpr *CE) {
for (const auto *Arg : CE->arguments()) {
+ Arg = Arg->IgnoreImplicit();
+
if (isa<CXXStdInitializerListExpr>(Arg) || isa<InitListExpr>(Arg))
return true;
// Check whether we implicitly construct a class from a
// std::initializer_list.
- if (const auto *ImplicitCE =
- dyn_cast<CXXConstructExpr>(Arg->IgnoreImplicit())) {
+ if (const auto *ImplicitCE = dyn_cast<CXXConstructExpr>(Arg)) {
if (ImplicitCE->isStdInitListInitialization())
return true;
}
Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp?rev=360231&r1=360230&r2=360231&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp Wed May 8 01:52:18 2019
@@ -273,6 +273,14 @@ void initialization(int T, Base b) {
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use std::make_unique instead
// CHECK-FIXES: std::make_unique<APair>(APair{T, 1});
+ // Check aggregate init with intermediate temporaries.
+ std::unique_ptr<APair> PAggrTemp = std::unique_ptr<APair>(new APair({T, 1}));
+ // CHECK-MESSAGES: :[[@LINE-1]]:38: warning: use std::make_unique instead
+ // CHECK-FIXES: std::unique_ptr<APair> PAggrTemp = std::unique_ptr<APair>(new APair({T, 1}));
+ PAggrTemp.reset(new APair({T, 1}));
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use std::make_unique instead
+ // CHECK-FIXES: PAggrTemp.reset(new APair({T, 1}));
+
// Test different kinds of initialization of the pointee, when the unique_ptr
// is initialized with braces.
More information about the cfe-commits
mailing list