ASTContext::OMPTraitInfoVector: Use unique_ptr to simplify memory management
authorDavid Blaikie <dblaikie@gmail.com>
Wed, 29 Apr 2020 03:18:01 +0000 (20:18 -0700)
committerDavid Blaikie <dblaikie@gmail.com>
Wed, 29 Apr 2020 05:31:16 +0000 (22:31 -0700)
clang/include/clang/AST/ASTContext.h
clang/lib/AST/ASTContext.cpp

index 82b8a51..cd7021a 100644 (file)
@@ -3002,7 +3002,7 @@ public:
 private:
   /// All OMPTraitInfo objects live in this collection, one per
   /// `pragma omp [begin] declare variant` directive.
-  SmallVector<OMPTraitInfo *, 4> OMPTraitInfoVector;
+  SmallVector<std::unique_ptr<OMPTraitInfo>, 4> OMPTraitInfoVector;
 };
 
 /// Utility function for constructing a nullary selector.
index 9b07a88..612f6ee 100644 (file)
@@ -1006,9 +1006,6 @@ ASTContext::~ASTContext() {
 
   for (APValue *Value : APValueCleanups)
     Value->~APValue();
-
-  // Destroy the OMPTraitInfo objects that life here.
-  llvm::DeleteContainerPointers(OMPTraitInfoVector);
 }
 
 void ASTContext::setTraversalScope(const std::vector<Decl *> &TopLevelDecls) {
@@ -11011,6 +11008,6 @@ void ASTContext::getFunctionFeatureMap(llvm::StringMap<bool> &FeatureMap,
 }
 
 OMPTraitInfo &ASTContext::getNewOMPTraitInfo() {
-  OMPTraitInfoVector.push_back(new OMPTraitInfo());
+  OMPTraitInfoVector.emplace_back(new OMPTraitInfo());
   return *OMPTraitInfoVector.back();
 }