Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp =================================================================== --- clang-tidy/modernize/MakeSmartPtrCheck.cpp +++ clang-tidy/modernize/MakeSmartPtrCheck.cpp @@ -375,6 +375,17 @@ // smart_ptr(new Pair{first, second}); // Has to be replaced with: // smart_ptr(Pair{first, second}); + // + // The fix (std::make_unique) requires to see the copy constructor of + // Pair, so we don't generate fix if the copy consturctor is not visible + // or deleted. + if (const auto *RD = New->getType()->getPointeeCXXRecordDecl()) { + for (const auto *Ctor : RD->ctors()) { + if (Ctor->isCopyConstructor() && + (Ctor->isDeleted() || Ctor->getAccess() == AS_private)) + return false; + } + } InitRange = SourceRange( New->getAllocatedTypeSourceInfo()->getTypeLoc().getBeginLoc(), New->getInitializer()->getSourceRange().getEnd()); Index: test/clang-tidy/modernize-make-unique.cpp =================================================================== --- test/clang-tidy/modernize-make-unique.cpp +++ test/clang-tidy/modernize-make-unique.cpp @@ -32,6 +32,10 @@ struct Empty {}; +struct NoCopyCtor { + NoCopyCtor(const NoCopyCtor&) = delete; +}; + struct E { E(std::initializer_list); E(); @@ -270,6 +274,11 @@ // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: use std::make_unique instead // CHECK-FIXES: std::unique_ptr PEmpty = std::make_unique(Empty{}); + // No fixes for classes with deleted copy constructor. + std::unique_ptr PNoCopyCtor = std::unique_ptr(new NoCopyCtor{}); + // CHECK-MESSAGES: :[[@LINE-1]]:45: warning: use std::make_unique instead + // CHECK-FIXES: std::unique_ptr PNoCopyCtor = std::unique_ptr(new NoCopyCtor{}); + // Initialization with default constructor. std::unique_ptr PE1 = std::unique_ptr(new E{}); // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead