c++ - 编译对齐的结构在 GCC 中给出奇怪的警告

标签 c++ gcc struct g++ alignment

我们有多个结构,它们是 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/

相关文章:

c++ - 在匿名结构中包装灵活数组时,MSVC 结构布局发生变化?

c++ - 如何实现梯度高斯模糊?

c - 为什么在终端中直接使用 gcc 编译可以工作,而使用 make 文件则不行?

c - gdb 通过指向错误的代码行显示不正确的回溯

java - JNI 以 "undefined symbol"退出

c - 初始化包含指向其自身类型的指针的常量结构

c++ - 从 vector<BSTR> 获取指向 BSTR 的指针

c# - 传递一个成员函数,如 C++ 中的 std::function(如 C# 中)

c++ - 使用结构统计()

C 创建超过一定大小的结构数组会导致崩溃