gcc过度对齐的新支持(alignas) [英] gcc over-aligned new support (alignas )
问题描述
我很难找到有关GCC新对齐警告和gcc -faligned-new选项的更多信息.在gcc 7.2.0上编译(不带--std = c ++ 17),并尝试定义对齐的结构,例如:
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();
给我以下警告和建议:
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
我了解默认情况下new
仅返回对齐至alignof( std::max_align_t )
的内存(对我来说这是16),但是我不清楚的是,如果我通过-faligned-new,gcc现在将强制执行正确的操作代表我new
的新对齐方式?
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?
不幸的是,关于此的gcc文档非常缺乏.
Unfortunately the gcc documentation on this is extremely lacking.