public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Jack Lloyd <lloyd@randombit.net>
Cc: gcc-help@gcc.gnu.org
Subject: Re: std::vector<__m128i> with non-standard allocators
Date: Mon, 11 Jun 2012 19:21:00 -0000	[thread overview]
Message-ID: <CAH6eHdQOFdvKLnFfVxA8XB4rcauwiPnJaaOZMK_v5vHKbbh8HA@mail.gmail.com> (raw)
In-Reply-To: <20120611185038.GN28623@randombit.net>

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.

      reply	other threads:[~2012-06-11 19:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-11 17:45 Jack Lloyd
2012-06-11 17:57 ` Jonathan Wakely
2012-06-11 18:50   ` Jack Lloyd
2012-06-11 19:21     ` Jonathan Wakely [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAH6eHdQOFdvKLnFfVxA8XB4rcauwiPnJaaOZMK_v5vHKbbh8HA@mail.gmail.com \
    --to=jwakely.gcc@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=lloyd@randombit.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).