I'm having some difficulty finding more information about GCC's aligned-new warning and the gcc -faligned-new option. Compiling on gcc 7.2.0 (without --std=c++17) and trying to define an aligned struct such as:
struct alignas(64) Foo { int x; }
Just doing a plain old:
Foo * f = new Foo();
Gives me the following warning and suggestion:
alignas.cpp:36:25: warning: ‘new’ of type ‘Foo’ with extended alignment 64 [-Waligned-new=]
Foo * f = new Foo();
^
alignas.cpp:36:25: note: uses ‘void* operator new(long unsigned int)’, which does not have an alignment parameter
alignas.cpp:36:25: note: use ‘-faligned-new’ to enable C++17 over-aligned new support
I understand that by default new
will only return memory aligned up to alignof( std::max_align_t )
( which is 16 for me ), but what's not clear to me is that if I pass -faligned-new, will gcc now enforce proper new alignment of new
on my behalf?
Unfortunately the gcc documentation on this is extremely lacking.
See Question&Answers more detail:os