Skip to content

Commit 37ab7fd

Browse files
committed
Correctly print the type in modernize-make-unique.
Summary: Take into account the current LangOptions the check has to add back the template argument. Reviewers: klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D13983 llvm-svn: 251013
1 parent 1d88d6f commit 37ab7fd

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ void MakeUniqueCheck::check(const MatchFinder::MatchResult &Result) {
7979
// If the template argument is missing (because it is part of the alias)
8080
// we have to add it back.
8181
ConstructCallEnd = ConstructCallStart.getLocWithOffset(ExprStr.size());
82-
Diag << FixItHint::CreateInsertion(ConstructCallEnd,
83-
"<" + Type->getAsString() + ">");
82+
Diag << FixItHint::CreateInsertion(
83+
ConstructCallEnd, "<" + Type->getAsString(getLangOpts()) + ">");
8484
} else {
8585
ConstructCallEnd = ConstructCallStart.getLocWithOffset(LAngle);
8686
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,18 @@ void aliases() {
163163
// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use std::make_unique instead
164164
// CHECK-FIXES: IntPtr Typedef = std::make_unique<int>();
165165

166+
// We use 'bool' instead of '_Bool'.
167+
typedef std::unique_ptr<bool> BoolPtr;
168+
BoolPtr BoolType = BoolPtr(new bool);
169+
// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: use std::make_unique instead
170+
// CHECK-FIXES: BoolPtr BoolType = std::make_unique<bool>();
171+
172+
// We use 'Base' instead of 'struct Base'.
173+
typedef std::unique_ptr<Base> BasePtr;
174+
BasePtr StructType = BasePtr(new Base);
175+
// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: use std::make_unique instead
176+
// CHECK-FIXES: BasePtr StructType = std::make_unique<Base>();
177+
166178
#define PTR unique_ptr<int>
167179
std::unique_ptr<int> Macro = std::PTR(new int);
168180
// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: use std::make_unique instead

0 commit comments

Comments
 (0)