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: "bangerth at dealii dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 8 Jun 2004 19:25:25 -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 bangerth at dealii dot org 2004-06-08 19:25 -------
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. Why not
struct AlignTag {
AlignTag (int alignment);
//...
};
operator new (size_t, AlignTag)
and convert
new Vector4[200];
into
new (__gnu_cxx::AlignTag(__alignof (Vector4)) Vector4[200];
Having something like
template <int> struct Alignment {};
template <int N> operator new (size_t, Alignment<N>);
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... ;-)
W.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15795