From 239f45348de7368078b525efbf6fac1085a433ab Mon Sep 17 00:00:00 2001 From: Ryan Prichard Date: Thu, 20 Jul 2023 20:04:42 -0700 Subject: Add InlineStdAllocator::rebind struct member Newer versions of libc++ (as well as libstdc++) require this of allocators. This member is needed for std::allocator_traits>::rebind_alloc, which contains a typedef for InlineStdAllocator. I believe this requirement was always present, but libc++ is checking for it now. AFAICT, the STL wouldn't be able to construct an InlineStdAllocator, because there is no default constructor, and the copy constructor wouldn't accept a reference to InlineStdAllocator. Perhaps that's OK because this allocator is only used with std::vector, not (say) std::list or std::map, which actually need to allocate internal node types. std::allocator_traits::rebind_alloc can automatically handle custom allocators with type parameters, but not with non-type parameters (i.e. It can't handle "size_t SIZE = 4"). See https://stackoverflow.com/a/34863387. Bug: b/175635923 Test: treehugger Change-Id: I0cceb47ab780414202cef1ed54fa7deb3773d01a --- libs/ui/include/ui/FatVector.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'libs') diff --git a/libs/ui/include/ui/FatVector.h b/libs/ui/include/ui/FatVector.h index cb61e6a320..494272b1a8 100644 --- a/libs/ui/include/ui/FatVector.h +++ b/libs/ui/include/ui/FatVector.h @@ -65,6 +65,17 @@ public: free(p); } } + + // The STL checks that this member type is present so that + // std::allocator_traits>::rebind_alloc + // works. std::vector won't be able to construct an + // InlineStdAllocator, because InlineStdAllocator has no + // default constructor, but vector presumably doesn't rebind the allocator + // because it doesn't allocate internal node types. + template + struct rebind { + typedef InlineStdAllocator other; + }; Allocation& mAllocation; }; -- cgit v1.2.3-59-g8ed1b