From bedfa6a49bb419711209ee52d21db71b4e4b8df5 Mon Sep 17 00:00:00 2001 From: Alex Rousskov Date: Mon, 18 May 2020 21:42:05 +0000 Subject: [PATCH] Fix PoolingAllocator build errors with older GCCs (#632) error: no class template named rebind in class PoolingAllocator GCC v4.8.4 (at least) does not fully implement C++11 Allocator-related APIs, forcing the developer to manually provide Allocator traits that are supposed to come automatically via std::allocator_traits. The problem may only manifest itself when using a custom allocator with types such as std::map and std::list that allocate wrapper objects instead of Ts. For example, std::vector is unaffected. --- src/mem/PoolingAllocator.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/mem/PoolingAllocator.h b/src/mem/PoolingAllocator.h index 037efca595..ff5de1094c 100644 --- a/src/mem/PoolingAllocator.h +++ b/src/mem/PoolingAllocator.h @@ -22,6 +22,23 @@ public: template PoolingAllocator(const PoolingAllocator &) noexcept {} value_type *allocate(std::size_t n) { return static_cast(memAllocRigid(n*sizeof(value_type))); } void deallocate(value_type *vp, std::size_t n) noexcept { memFreeRigid(vp, n*sizeof(value_type)); } + + // The following declarations are only necessary for compilers that do not + // fully support C++11 Allocator-related APIs, such as GCC v4.8. + // TODO: Remove after dropping support for such compilers. + + using size_type = size_t; + using pointer = Value*; + using const_pointer = const Value*; + using reference = Value&; + using const_reference = const Value&; + + template + struct rebind { + typedef PoolingAllocator other; + }; + + template void destroy(OtherValue *p) { p->~OtherValue(); } }; template -- 2.47.3