diff options
Diffstat (limited to 'clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp')
| -rw-r--r-- | clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp index 54fc567a489..c8d66cadd6d 100644 --- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp @@ -387,6 +387,19 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag, // smart_ptr<Pair>(new Pair{first, second}); // Has to be replaced with: // smart_ptr<Pair>(Pair{first, second}); + // + // The fix (std::make_unique) needs to see copy/move constructor of + // Pair. If we found any invisible or deleted copy/move constructor, we + // stop generating fixes -- as the C++ rule is complicated and we are less + // certain about the correct fixes. + if (const CXXRecordDecl *RD = New->getType()->getPointeeCXXRecordDecl()) { + if (llvm::find_if(RD->ctors(), [](const CXXConstructorDecl *Ctor) { + return Ctor->isCopyOrMoveConstructor() && + (Ctor->isDeleted() || Ctor->getAccess() == AS_private); + }) != RD->ctor_end()) { + return false; + } + } InitRange = SourceRange( New->getAllocatedTypeSourceInfo()->getTypeLoc().getBeginLoc(), New->getInitializer()->getSourceRange().getEnd()); |

