std::vector<__m128i> with non-standard allocators

Jonathan Wakely jwakely.gcc@gmail.com
Mon Jun 11 17:57:00 GMT 2012


On 11 June 2012 18:44, Jack Lloyd wrote:
>
> I'm having a problem using a custom allocator with a std::vector of
> __m128i values, where _Destroy in stl_construct.h will invoke destroy
> even on objects with trivial destructors with any allocator other than
> std::alloctor.

That's intentional, it's not known whether a user-defined allocator
wants to do anything interesting in the destroy function.  We probably
could specialize it to know about __gnu_cxx::new_allocator though.

>
> Interestingly this appears to be due to the fact that for a freestanding
>
> template<typename U> void destroy(U* p) { p->~U(); }
>
> GCC has no issues with
>
> long l;
> destroy(&l);
>
> but rejects
>
> __m128i m;
> destroy(&m);
>
> with an error like the one above.
>
> Is this behavior intentional/expected?

The C++ standard says that in a psuedo-destructor call (i.e. an
expression like p->~U() for a non-class type) the operand shall be a
scalar type, which would seem to rule out vector types (but then the
standard says nothing about them anyway.)

You could either specialize the allocator's destroy function for the
case of __m128i so it does nothing, or file a bug asking for
pseudo-destructor calls to be allowed on types like __m128i.



More information about the Gcc-help mailing list