[Bug c++/15795] No way to teach operator new anything about alignment requirements
jason at redhat dot com
gcc-bugzilla@gcc.gnu.org
Tue Jun 8 20:04:00 GMT 2004
------- Additional Comments From jason at redhat dot com 2004-06-08 20:04 -------
Subject: Re: No way to teach operator new anything about
alignment requirements
On 8 Jun 2004 19:25:27 -0000, "bangerth at dealii dot org" <gcc-bugzilla@gcc.gnu.org> wrote:
> I we are to provide a workaround, I think that the signature you
> propose, i.e.
> operator new (size_t size, enum align_tag, size_t align);
> may not be a good idea, the second and third argument being an integer. This
> is just way too common and asking for trouble.
I don't think it would actually be a problem, since enums are distinct
types. But I understand your concern, since they do promote to integers,
and I'm not opposed to using a struct instead.
> Having something like
> template <int> struct Alignment {};
> template <int N> operator new (size_t, Alignment<N>);
Or
template <typename T> struct Alignment
{
static const size_t alignment = __alignof (T);
};
template <typename T> inline void *
operator new (size_t size, Alignment<T> align)
{
return align_new (size, align.alignment);
}
...
new (Alignment<Vector4>) Vector4[200];
Yes, that seems like a cleaner syntax for explicit placement new.
> may also be a neat possibility if we use SFINAE to provide
> template <int N>
> typename SFINAE<(N<=STD_ALIGNMENT),void*> operator new (size_t,Alignment<T>)
> and the opposite case as two overloads, and let the compiler pick which
> one it wants to call. This way we can switch at compile time which allocation
> function shall be called. But I think I'm carried away... ;-)
I'm not familiar with SFINAE.
Jason
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15795
More information about the Gcc-bugs
mailing list