Index: clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp +++ clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp @@ -16,6 +16,17 @@ namespace tidy { namespace modernize { +namespace { +StringRef GetNewExprName(const CXXNewExpr *NewExpr, + const SourceManager &SM, + const LangOptions &Lang) { + return Lexer::getSourceText( + CharSourceRange::getTokenRange( + NewExpr->getAllocatedTypeSourceInfo()->getTypeLoc().getSourceRange()), + SM, Lang); +} +} // namespace + const char MakeSmartPtrCheck::PointerType[] = "pointerType"; const char MakeSmartPtrCheck::ConstructorCall[] = "constructorCall"; const char MakeSmartPtrCheck::ResetCall[] = "resetCall"; @@ -87,7 +98,7 @@ StringRef ExprStr = Lexer::getSourceText( CharSourceRange::getCharRange( ConstructCallStart, Construct->getParenOrBraceRange().getBegin()), - SM, LangOptions(), &Invalid); + SM, getLangOpts(), &Invalid); if (Invalid) return; @@ -102,7 +113,8 @@ // we have to add it back. ConstructCallEnd = ConstructCallStart.getLocWithOffset(ExprStr.size()); Diag << FixItHint::CreateInsertion( - ConstructCallEnd, "<" + Type->getAsString(getLangOpts()) + ">"); + ConstructCallEnd, + "<" + GetNewExprName(New, SM, getLangOpts()).str() + ">"); } else { ConstructCallEnd = ConstructCallStart.getLocWithOffset(LAngle); } @@ -144,7 +156,7 @@ Diag << FixItHint::CreateReplacement( CharSourceRange::getCharRange(OperatorLoc, ExprEnd), (llvm::Twine(" = ") + makeSmartPtrFunctionName + "<" + - New->getAllocatedType().getAsString(getLangOpts()) + ">") + GetNewExprName(New, SM, getLangOpts()) + ">") .str()); if (Expr->isArrow()) Index: clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp +++ clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp @@ -49,6 +49,14 @@ struct Empty {}; +namespace { +class Foo {}; +} // namespace + +namespace bar { +class Bar {}; +} // namespace bar + template using unique_ptr_ = std::unique_ptr; @@ -239,6 +247,20 @@ std::unique_ptr PEmpty = std::unique_ptr(new Empty{}); // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: use std::make_unique instead // CHECK-FIXES: std::unique_ptr PEmpty = std::make_unique(Empty{}); + + std::unique_ptr FF = std::unique_ptr(new Foo()); + // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: + // CHECK-FIXES: std::unique_ptr FF = std::make_unique(); + FF.reset(new Foo()); + // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: + // CHECK-FIXES: FF = std::make_unique(); + + std::unique_ptr BB = std::unique_ptr(new bar::Bar()); + // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: + // CHECK-FIXES: std::unique_ptr BB = std::make_unique(); + BB.reset(new bar::Bar()); + // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: + // CHECK-FIXES: BB = std::make_unique(); } void aliases() {