[llvm] 2984156 - Make SmallVectorImpl destructor protected (#71746)

via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 9 08:52:52 PST 2023


Author: Andy Kaylor
Date: 2023-11-09T08:52:47-08:00
New Revision: 2984156fd34a6969c7461b228d90b72711e3797c

URL: https://github.com/llvm/llvm-project/commit/2984156fd34a6969c7461b228d90b72711e3797c
DIFF: https://github.com/llvm/llvm-project/commit/2984156fd34a6969c7461b228d90b72711e3797c.diff

LOG: Make SmallVectorImpl destructor protected (#71746)

Because the SmallVectorImpl destructor is not virtual, the destructor of
derived classes will not be called if pointers to the SmallVectorImpl
class are deleted directly. Making the SmallVectorImpl destructor
protected will prevent this.

Added: 
    

Modified: 
    llvm/include/llvm/ADT/SmallVector.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h
index 53a107b1574c6a3..2e6d2dc6ce90a2c 100644
--- a/llvm/include/llvm/ADT/SmallVector.h
+++ b/llvm/include/llvm/ADT/SmallVector.h
@@ -601,9 +601,6 @@ class SmallVectorImpl : public SmallVectorTemplateBase<T> {
     RHS.resetToSmall();
   }
 
-public:
-  SmallVectorImpl(const SmallVectorImpl &) = delete;
-
   ~SmallVectorImpl() {
     // Subclass has already destructed this vector's elements.
     // If this wasn't grown from the inline copy, deallocate the old space.
@@ -611,6 +608,9 @@ class SmallVectorImpl : public SmallVectorTemplateBase<T> {
       free(this->begin());
   }
 
+public:
+  SmallVectorImpl(const SmallVectorImpl &) = delete;
+
   void clear() {
     this->destroy_range(this->begin(), this->end());
     this->Size = 0;


        


More information about the llvm-commits mailing list