[llvm] Make SmallVectorImpl destructor protected (PR #71746)

via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 8 15:30:16 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-adt

Author: Andy Kaylor (andykaylor)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/71746.diff


1 Files Affected:

- (modified) llvm/include/llvm/ADT/SmallVector.h (+3-3) 


``````````diff
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;

``````````

</details>


https://github.com/llvm/llvm-project/pull/71746


More information about the llvm-commits mailing list