我们有多个结构,它们是 16 字节对齐的。 在以前版本的 GCC 中一切正常。 自从我们升级到 GCC 4.8.2(之前我们使用 4.6)后,我们收到了一堆关于这些结构的警告。
一个示例结构为:
typedef struct _STRUCT
{
_STRUCT(): a(0),
b(0) {};
uint32_t a;
uint32_t b;
} STRUCT __attribute__((aligned (16)));
编译此代码会在使用此 strcut 的地方引发以下警告:
warning: ignoring attributes on template argument '_STRUCT' [enabled by default]
我真的不明白,这个警告试图告诉我什么,谷歌搜索也没有帮助。
最佳答案
根据C++ PATCH for c++/48138 (losing __attribute ((aligned)) on template argument),这看起来是有目的的,它说:
...except that we don't want to retain attributes on template type arguments, since they aren't part of mangling, so you could get a class template instantiation that is the same type regardless of the alignment of the argument, but the effective argument varies depending on which alignment was first used to instantiate it.
The PR suggests a warning when we drop the attributes, which makes sense. This patch does not yet provide the warning in the case of function templates, but does for class templates. Warning for function templates will wait until after Nathan's patch to improve template overloading diagnostics.
所以看起来警告是新的,但它的处理方式是一样的。
关于c++ - 编译对齐的结构在 GCC 中给出奇怪的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22512235/