From: Nico Weber Date: Mon, 15 Jul 2019 17:20:34 +0000 (+0000) Subject: Use a unique_ptr instead of manual memory management for CustomDiagInfo X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a50943994bf8a45e1929d65c0c7c5b69c2dd3bc7;p=clang Use a unique_ptr instead of manual memory management for CustomDiagInfo git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@366085 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticIDs.h b/include/clang/Basic/DiagnosticIDs.h index fccd534be3..5b9391b5a4 100644 --- a/include/clang/Basic/DiagnosticIDs.h +++ b/include/clang/Basic/DiagnosticIDs.h @@ -169,7 +169,7 @@ public: private: /// Information for uniquing and looking up custom diags. - diag::CustomDiagInfo *CustomDiagInfo; + std::unique_ptr CustomDiagInfo; public: DiagnosticIDs(); diff --git a/lib/Basic/DiagnosticIDs.cpp b/lib/Basic/DiagnosticIDs.cpp index f189e5de49..e30e3753d1 100644 --- a/lib/Basic/DiagnosticIDs.cpp +++ b/lib/Basic/DiagnosticIDs.cpp @@ -311,11 +311,9 @@ namespace clang { // Common Diagnostic implementation //===----------------------------------------------------------------------===// -DiagnosticIDs::DiagnosticIDs() { CustomDiagInfo = nullptr; } +DiagnosticIDs::DiagnosticIDs() {} -DiagnosticIDs::~DiagnosticIDs() { - delete CustomDiagInfo; -} +DiagnosticIDs::~DiagnosticIDs() {} /// getCustomDiagID - Return an ID for a diagnostic with the specified message /// and level. If this is the first request for this diagnostic, it is @@ -325,7 +323,7 @@ DiagnosticIDs::~DiagnosticIDs() { /// mapped to a unique DiagID. unsigned DiagnosticIDs::getCustomDiagID(Level L, StringRef FormatString) { if (!CustomDiagInfo) - CustomDiagInfo = new diag::CustomDiagInfo(); + CustomDiagInfo.reset(new diag::CustomDiagInfo()); return CustomDiagInfo->getOrCreateDiagID(L, FormatString, *this); }