https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69571
Bug ID: 69571
Summary: [C++11] invalid alignas on a typedef accepted, reduces
alignment
Product: gcc
Version: 6.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: ---
GCC disregards some cases of invalid application of the alignment specifier
(issuing a warning pointing them out) but misses others.
In the program below, the last three instances the alignas specifier are
invalid for two reasons: first, the specifier is not permitted on typedefs, and
second, it's not allowed to relax the alignment requirement of a type.
$ cat z.c && /build/gcc-trunk/gcc/xgcc -B /build/gcc-trunk/gcc -O2 -S -Wall
-Wextra -Wpedantic -std=c++14 -xc++ z.c
typedef struct A { alignas (32) int c; } A;
#define Assert(e) static_assert (e, #e)
typedef alignas (1) A A1_1;
Assert (alignof (A1_1) == alignof (A));
typedef A alignas (1) A1_2;
Assert (alignof (A1_2) == alignof (A));
typedef A A1_3 alignas (1);
Assert (alignof (A1_3) == alignof (A));
z.c:5:9: warning: attribute ignored [-Wattributes]
typedef alignas (1) A A1_1;
^~~~~~~
z.c:5:9: note: an attribute that appertains to a type-specifier is ignored
z.c:8:11: warning: attribute ignored [-Wattributes]
typedef A alignas (1) A1_2;
^~~~~~~
z.c:8:11: note: an attribute that appertains to a type-specifier is ignored
z.c:3:19: error: static assertion failed: alignof (A1_3) == alignof (A)
#define Assert(e) static_assert (e, #e)
^
z.c:12:1: note: in expansion of macro ‘Assert’
Assert (alignof (A1_3) == alignof (A));
^~~~~~
Clang rejects all three instances with a hard error.