[Bug libstdc++/21609] array_allocator vs rebind & templated constructor
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Jan 29 16:23:00 GMT 2014
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.
More information about the Gcc-bugs
mailing list