http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21609

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |NEW

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It's worse than described:


// should work for any conforming Allocator
template<typename T, typename A>
void rebind(const A& a)
{
#if __cplusplus >= 201103L
  typedef std::allocator_traits<A>::template rebind_alloc<T> A2;
#else
  typedef typename A::template rebind<T>::other A2;
#endif
  A2 a2(a);
  T* p = a2.allocate(1);
  a2.deallocate(p, 1);
}

#include <ext/array_allocator.h>

int main()
{
  typedef std::tr1::array<char, 16> array;
  array mem;
  typedef __gnu_cxx::array_allocator<char, array> char_allocator;
  char_allocator a(&mem);
  rebind<int>(a);
}

This fails to compile because the rebound allocator still has array<char,16> as
its array_type, but that means _M_array->begin() is char* not int* so line 151
in array_allocator.h cannot be compiled.

Even if you alter the array_type when rebinding (which no code expecting a
conforming allocator will ever do) it fails at run-time for the reason Paolo
gave:

#include <ext/array_allocator.h>

int main()
{
  typedef std::tr1::array<char, 16> array;
  array mem;
  typedef __gnu_cxx::array_allocator<char, array> char_allocator;
  char_allocator a(&mem);

  typedef std::tr1::array<int, 4> iarray;
  typedef typename char_allocator::template rebind<int, iarray>::other A2;
  A2 a2(a);
  int* p = a2.allocate(1);   // throws
  a2.deallocate(p, 1);
}

This makes array_allocator non-conforming.

I propose we deprecate it and then remove it.

Reply via email to