https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81756
Bug ID: 81756
Summary: type attributes silently ignored on type declarations
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
When the C11 _Alignas specifier is used on a struct declaration GCC issues a
helpful warning pointing out that the attribute is meaningless. The warning is
issued unconditionally with no option to control it. This should be corrected
and the warning should be enabled under a designated option (e.g., -Wattributes
or -Wignored-attributes).
However, when the equivalent attribute aligned is used the same way GCC
silently ignores it. It would help prevent subtle bugs to have GCC issue a
warning in this case to let the user know that the attribute has no effect.
The test case below illustrates the problem.
$ cat b.c && gcc -O2 -S -Wall -Wextra b.c
#define A(e) _Static_assert ((e), #e)
_Alignas (32) struct NotAligned; // ignored with warning (good)
struct NotAligned { long i; };
A (_Alignof (struct NotAligned) == _Alignof (long)); // passes
struct __attribute__ ((aligned (32))) // silently ignored
Aligned32;
struct Aligned32 { long i; };
A (_Alignof (struct Aligned32) == 32); // FAILS
b.c:3:22: warning: useless ‘_Alignas’ in empty declaration
_Alignas (32) struct NotAligned; // ignored with warning (good)
^~~~~~~~~~
b.c:1:14: error: static assertion failed: "_Alignof (struct Aligned32) == 32"
#define A(e) _Static_assert ((e), #e)
^~~~~~~~~~~~~~
b.c:15:1: note: in expansion of macro ‘A’
A (_Alignof (struct Aligned32) == 32); // FAILS
^