Browse Source

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
Nico Weber 6 years ago
parent
commit
a50943994b
2 changed files with 4 additions and 6 deletions
  1. 1 1
      include/clang/Basic/DiagnosticIDs.h
  2. 3 5
      lib/Basic/DiagnosticIDs.cpp

+ 1 - 1
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<diag::CustomDiagInfo> CustomDiagInfo;
 
 public:
   DiagnosticIDs();

+ 3 - 5
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);
 }