]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
alloc-pool: Support non-default constructors
authorRichard Sandiford <rdsandiford@googlemail.com>
Thu, 7 May 2026 20:18:02 +0000 (21:18 +0100)
committerRichard Sandiford <rdsandiford@googlemail.com>
Thu, 7 May 2026 20:18:02 +0000 (21:18 +0100)
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.

gcc/alloc-pool.h

index 60e17067794810eaa644867ac5c309d2069f1445..2a54cdacf103397564d497774626c5580a696d81 100644 (file)
@@ -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