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.
Tested on aarch64-linux-gnu, powerpc64le-linux-gnu & x86_64-linux-gnu.
OK to install?
Richard
gcc/
* alloc-pool.h (object_allocator::allocate): Generalize to handle
non-default constructors.
---
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 60e17067794..2a54cdacf10 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
--
2.54.0