Author: David Blaikie Date: 2020-04-28T17:45:07-07:00 New Revision: c98a7e9bcc26a13d5e0b3fd199a7d0298777d85e
URL: https://github.com/llvm/llvm-project/commit/c98a7e9bcc26a13d5e0b3fd199a7d0298777d85e DIFF: https://github.com/llvm/llvm-project/commit/c98a7e9bcc26a13d5e0b3fd199a7d0298777d85e.diff LOG: AllocatedCXCodeCompleteResults::DiagnosticWrappers: use unique_ptr to simplify memory management Added: Modified: clang/tools/libclang/CIndexCodeCompletion.cpp Removed: ################################################################################ diff --git a/clang/tools/libclang/CIndexCodeCompletion.cpp b/clang/tools/libclang/CIndexCodeCompletion.cpp index 1311f66ce0bc..6685c892749e 100644 --- a/clang/tools/libclang/CIndexCodeCompletion.cpp +++ b/clang/tools/libclang/CIndexCodeCompletion.cpp @@ -254,7 +254,7 @@ struct AllocatedCXCodeCompleteResults : public CXCodeCompleteResults { SmallVector<StoredDiagnostic, 8> Diagnostics; /// Allocated API-exposed wrappters for Diagnostics. - SmallVector<CXStoredDiagnostic *, 8> DiagnosticsWrappers; + SmallVector<std::unique_ptr<CXStoredDiagnostic>, 8> DiagnosticsWrappers; IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts; @@ -371,7 +371,6 @@ AllocatedCXCodeCompleteResults::AllocatedCXCodeCompleteResults( } AllocatedCXCodeCompleteResults::~AllocatedCXCodeCompleteResults() { - llvm::DeleteContainerPointers(DiagnosticsWrappers); delete [] Results; for (unsigned I = 0, N = TemporaryBuffers.size(); I != N; ++I) @@ -914,10 +913,12 @@ clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *ResultsIn, if (!Results || Index >= Results->Diagnostics.size()) return nullptr; - CXStoredDiagnostic *Diag = Results->DiagnosticsWrappers[Index]; + CXStoredDiagnostic *Diag = Results->DiagnosticsWrappers[Index].get(); if (!Diag) - Results->DiagnosticsWrappers[Index] = Diag = - new CXStoredDiagnostic(Results->Diagnostics[Index], Results->LangOpts); + Diag = (Results->DiagnosticsWrappers[Index] = + std::make_unique<CXStoredDiagnostic>( + Results->Diagnostics[Index], Results->LangOpts)) + .get(); return Diag; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits