[libcxx-commits] [PATCH] D133638: [libc++] static_assert that rebinding the allocator works as expected

Jordan Rupprecht via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Oct 11 11:32:53 PDT 2022


rupprecht added a comment.

I'm seeing some build failures that don't seem to be the intended effect of this patch:

  allocator_traits.h:159:57: error: no member named 'rebind' in 'FooAllocator'
      using type _LIBCPP_NODEBUG = typename _Tp::template rebind<_Up>::other;
                                            ~~~~~         ^
  allocator_traits.h:172:1: note: in instantiation of template class 'std::__allocator_traits_rebind<FooAllocator, Foo, false>' requested here
  using __allocator_traits_rebind_t = typename __allocator_traits_rebind<_Alloc, _Tp>::type;
  ^
  allocator_traits.h:244:5: note: in instantiation of template type alias '__allocator_traits_rebind_t' requested here
      using rebind_alloc = __allocator_traits_rebind_t<allocator_type, _Tp>;
      ^
  allocator_traits.h:352:1: note: in instantiation of template type alias 'rebind_alloc' requested here
  using __rebind_alloc _LIBCPP_NODEBUG = typename _Traits::template rebind_alloc<_Tp>;
  ^
  vector:361:43: note: in instantiation of template type alias '__rebind_alloc' requested here
      static_assert(is_same<allocator_type, __rebind_alloc<__alloc_traits, value_type> >::value,
                                            ^
  foo.h:71:17: note: in instantiation of template class 'std::vector<Foo, FooAllocator>' requested here
    Foos foos_;

With the allocator definition being:

  class FooAllocator {
   public:
    using value_type = Foo;
    FooAllocator() = default;
  
    Foo* allocate(size_t num_objects);
  
    void deallocate(Foo* ptr, size_t num_objects);
  
    bool operator==(const FooAllocator&) const { return true; }
    bool operator!=(const FooAllocator&) const { return false; }
  };
  
  using Foos = std::vector<Foo, FooAllocator>;
  
  Foos foos_;

(obviously sanitized)

It seems this patch static_asserts that rebind works as expected, but in this case, FooAllocator does not implement rebind at all -- which seems to be expected to work, per https://eel.is/c++draft/allocator.requirements#general-98. And the build failure seems to be due to rebind not being implemented.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133638/new/

https://reviews.llvm.org/D133638



More information about the libcxx-commits mailing list