]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix PoolingAllocator build errors with older GCCs (#632)
authorAlex Rousskov <rousskov@measurement-factory.com>
Mon, 18 May 2020 21:42:05 +0000 (21:42 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Mon, 18 May 2020 21:42:10 +0000 (21:42 +0000)
    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<T> and std::list<T> that allocate wrapper
objects instead of Ts. For example, std::vector is unaffected.

src/mem/PoolingAllocator.h

index 037efca595e72708b96b29d5c2f6485807f393df..ff5de1094c0d9dd674ce58236a55cda676519cfc 100644 (file)
@@ -22,6 +22,23 @@ public:
     template <class Other> PoolingAllocator(const PoolingAllocator<Other> &) noexcept {}
     value_type *allocate(std::size_t n) { return static_cast<value_type*>(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 <class OtherValue>
+    struct rebind {
+      typedef PoolingAllocator<OtherValue> other;
+    };
+
+    template<typename OtherValue> void destroy(OtherValue *p) { p->~OtherValue(); }
 };
 
 template <class L, class R>