From: Alex Rousskov Date: Mon, 18 May 2020 21:42:05 +0000 (+0000) Subject: Fix PoolingAllocator build errors with older GCCs (#632) X-Git-Tag: 4.15-20210522-snapshot~117 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bedfa6a49bb419711209ee52d21db71b4e4b8df5;p=thirdparty%2Fsquid.git 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. --- 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