I'm having difficulty finding more information about the GCC-oriented new warning and the gcc -faligned-new option. Compiling on gcc 7.2.0 (without -std = C ++ 17) and attempting to define an aligned structure, such as:
struct alignas(64) Foo { int x; }
Just make a simple old one:
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 newonly memory tied to will return alignof( std::max_align_t )(for me it is 16), but it is not clear to me that if I pass -faligned-new, will gcc now apply the proper new alignment newon my behalf?
Unfortunately, gcc documentation on this subject is sorely lacking.
source
share