This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/15795] No way to teach operator new anything about alignment requirements
- From: "jason at redhat dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 8 Jun 2004 18:39:49 -0000
- Subject: [Bug c++/15795] No way to teach operator new anything about alignment requirements
- References: <20040603143635.15795.ma1flfs@bath.ac.uk>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From jason at redhat dot com 2004-06-08 18:39 -------
Subject: Re: No way to teach operator new anything about
alignment requirements
It would be possible for the compiler to implement this workaround
transparently, as an extension; i.e. if the new'd type has alignment
greater than MALLOC_ALIGN, use something like
operator new (size_t size, enum align_tag, size_t align);
i.e. translate
new Vector4[200];
into
new (__gnu_cxx::aligned, __alignof (Vector4)) Vector4[200];
But this would interact badly with overriding the default operator new.
I think that if glibc is unwilling to change the default alignment for
malloc, it doesn't make any sense for libstdc++ to change it in operator
new. The above workaround stands a good chance of breaking things if
implemented transparently.
So I think that the way to fix this problem is for users to implement the
workaround, possibly relying on the above operator new signature, to be
provided by libstdc++. Vector4::operator new would then be simplified to
void *operator new (size_t size)
{
return operator new (size, __gnu_cxx::aligned, __alignof (Vector4));
}
Thoughts?
Jason
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15795