Compiling alignment structure gives strange warning in GCC

We have several structures that are aligned by 16 bytes. In previous versions of GCC, everything worked fine. Since we upgraded to GCC 4.8.2 (previously we used 4.6), we get a bunch of warnings about these structures.

Example struct as:

typedef struct _STRUCT { _STRUCT(): a(0), b(0) {}; uint32_t a; uint32_t b; } STRUCT __attribute__((aligned (16))); 

Compiling this code generates the following warning that uses this line:

 warning: ignoring attributes on template argument '_STRUCT' [enabled by default] 

I really don't understand what this warning is trying to tell me, and a google search didn't help either.

+6
source share
2 answers

@ Shafiq Yagmur pushed me in the right direction. Inspecting the error message he mentioned gave me the correct answer:

... but the main problem is that alignment by typedefs is not supported. the attribute ((aligned)) in the template arguments seems to have no effect.

Source: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48138

This led to the position __attribute__(aligned(16)) being the key. If I put it either after the keyword structure or from the closing brace, the warning will disappear, for example:

 typedef struct __attribute__((aligned (16))) _STRUCT { 

or

  _STRUCT(): a(0), b(0) {}; uint32_t a; uint32_t b; } __attribute__((aligned (16))) STRUCT; 

The first is a proposal from a GCC document. http://gcc.gnu.org/onlinedocs/gcc/Type-Attributes.html

For an enumeration type, structure, or union, you can specify attributes either between the enum, struct, or union tag and the type name, or simply behind the closing brace of the definition. The previous syntax is preferred.

So, in the event that the first implementation set alignment for the typedef, the solution sets alignment for the structure that was the target in the first place.

+2
source

It looks like it was targeted according to the C ++ PATCH for C ++ / 48138 (losing __attribute ((aligned)) in the template argument) which says

... except that we don’t want to store attributes in template type arguments, since they are not part of mangling, so you can get an instance of a class template that is the same type, regardless of the alignment of the argument, but the effective argument changes depending on what kind of alignment was first used to create it.

PR offers a warning when we drop attributes, which makes sense. This patch does not yet give a warning in the case of function templates, but for class templates. A warning for function templates will wait until after the Nathan fix, the diagnostics of overloading templates is improved.

So it looks like the warning is new, but the way it was considered is the same.

+3
source

All Articles