https://gcc.gnu.org/g:56c9f39d2c703203014079b5a0a262ac22f8c3f2

commit r17-388-g56c9f39d2c703203014079b5a0a262ac22f8c3f2
Author: Richard Sandiford <[email protected]>
Date:   Thu May 7 21:18:02 2026 +0100

    alloc-pool: Support non-default constructors
    
    object_allocator only allowed allocations to use the default constructor.
    This patch generalises it to other constructors, in the same way as
    rtl-ssa does for obstack allocations.
    
    The first use case is likely to be Robin's backprop patch.
    
    gcc/
            * alloc-pool.h (object_allocator::allocate): Generalize to handle
            non-default constructors.

Diff:
---
 gcc/alloc-pool.h | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/gcc/alloc-pool.h b/gcc/alloc-pool.h
index 60e170677948..2a54cdacf103 100644
--- a/gcc/alloc-pool.h
+++ b/gcc/alloc-pool.h
@@ -499,10 +499,11 @@ public:
 
   /* Allocate memory for instance of type T and call a default constructor.  */
 
-  inline T *
-  allocate () ATTRIBUTE_MALLOC
+  template<typename... Ts>
+  inline ATTRIBUTE_MALLOC T *
+  allocate (Ts... args)
   {
-    return ::new (m_allocator.allocate ()) T;
+    return ::new (m_allocator.allocate ()) T (std::forward<Ts> (args)...);
   }
 
   /* Allocate memory for instance of type T and return void * that

Reply via email to