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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11 June 2012 19:50, Jack Lloyd wrote:
> On Mon, Jun 11, 2012 at 06:57:05PM +0100, Jonathan Wakely wrote:
>
>> 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.)
>
> Thanks, I had no realized that the standard allows that for scalar
> types.

You're not allowed to specialize templates from namespace std for
scalar types, but for your_custom_allocator or my_custom_allocator you
can specialize anything, or they could just be written to have special
handling for scalars without any specialization (e.g.
my_custom_allocator<int>::destroy(int*, size_t) could write to
std::cout every time it's called.)


>> 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.
>
> I considered specialization but that requires me to guess what vector
> types someone might want to use (the various AVX, NEON, and AltiVec
> types all seem reasonable in the context of the allocator I'm writing)
> and additionally pollute the namespace by pulling in headers to find
> the definitions, so I was hoping for another approach.
>
> It's definitely pretty unfortunate that this is rejected in that it
> seems (?) like the intent of the pseudo-destructor syntax is to ensure
> that p->~U() is always well formed precisely to allow uniform syntax
> for cases like this.

For scalar types, yes.  It's not valid to use a pseudo-destructor call
for non-scalar, non-class types e.g. this isn't valid:

typedef int array[2];
array a;
a.~array();

Vector types like __m128i aren't really part of the C++ type system,
so it's not entirely surprising they fall through the gaps between
well-defined features and extensions.

> I suppose I'll file a bug and hope that people
> working on the C++ FE agree this is a reasonable thing to support. It
> looks like Clang 3.1 also rejects, Intel C++ 12.1 and Visual C++ 2010
> accepts. Not sure about Comeau as the online compiler doesn't seem to
> know about emmintrin.h

I think the Comeau online compiler ensures no non-standard headers are usable.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux