]> granicus.if.org Git - clang/commitdiff
Use a unique_ptr instead of manual memory management for CustomDiagInfo
authorNico Weber <nicolasweber@gmx.de>
Mon, 15 Jul 2019 17:20:34 +0000 (17:20 +0000)
committerNico Weber <nicolasweber@gmx.de>
Mon, 15 Jul 2019 17:20:34 +0000 (17:20 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@366085 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticIDs.h
lib/Basic/DiagnosticIDs.cpp

index fccd534be350f433f88dc74e5b3e77c803b128e2..5b9391b5a45275f70c95601fc5e73b5901ea2a0d 100644 (file)
@@ -169,7 +169,7 @@ public:
 
 private:
   /// Information for uniquing and looking up custom diags.
-  diag::CustomDiagInfo *CustomDiagInfo;
+  std::unique_ptr<diag::CustomDiagInfo> CustomDiagInfo;
 
 public:
   DiagnosticIDs();
index f189e5de498a158a50e057710c9e2409198c49d7..e30e3753d193651e129587aea23dbcd16ec3b77e 100644 (file)
@@ -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);
 }