[Bug c++/69585] New: [C++ 11] parser errors mixing alignas, C++ 11 and GNU attributes on class declaration
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Feb 1 00:46:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69585
Bug ID: 69585
Summary: [C++ 11] parser errors mixing alignas, C++ 11 and GNU
attributes on class declaration
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: ---
The C++ parser seems to have trouble combining the C++11 alignas specifier and
the GNU __attribute__ specifier in the same class declaration. It also doesn't
like pairing C++11 attribute specifiers with GNU __attribute__. Pairing
alignas and the C++ 11 [[attribute]] syntax seems to work.
Clang does somewhat better (it handles GNU __attribute__ and C++11
[[attribute]] but it too chokes on alignas and GNU attributes and on C++
[[attribute]] and GNU __attribute__.
The following example shows the problematic interactions between C++ 11
alignas, C++ 11 [[gnu::may_alias]], and GNU __attribute__((mayalias)).
Since other similar syntactic combinations are accepted (such as the common
inline and __attribute__((always_inline))), I expected alignas and
__attribute__((whatever)) to be as well. I couldn't find anything about this
restriction is in manual.
$ cat v.c && /build/gcc-trunk/gcc/xgcc -B /build/gcc-trunk/gcc -O2 -S -Wall
-Wextra -Wpedantic -Wuninitialized -std=c++11 -xc++ v.c
struct __attribute__ ((aligned (2))) __attribute__ ((may_alias))
S1 { };
struct __attribute__ ((aligned (2))) [[gnu::may_alias]]
S2 { };
struct alignas (2) __attribute__ ((may_alias))
S3 { };
struct alignas (2) [[gnu::may_alias]]
S4 { };
struct __attribute__ ((may_alias)) __attribute__ ((aligned (2)))
S1_2 { };
struct [[gnu::may_alias]] __attribute__ ((aligned (2)))
S2_2 { };
struct __attribute__ ((may_alias)) alignas (2)
S3_2 { };
struct [[gnu::may_alias]] alignas (2)
S4_2 { };
v.c:4:38: error: expected identifier before ‘[’ token
struct __attribute__ ((aligned (2))) [[gnu::may_alias]]
^
v.c:4:38: warning: attribute ignored [-Wattributes]
v.c:4:38: note: an attribute that appertains to a type-specifier is ignored
v.c:7:20: error: expected identifier before ‘__attribute__’
struct alignas (2) __attribute__ ((may_alias))
^~~~~~~~~~~~~
v.c:17:27: error: expected identifier before ‘__attribute__’
struct [[gnu::may_alias]] __attribute__ ((aligned (2)))
^~~~~~~~~~~~~
v.c:20:36: error: expected identifier before ‘alignas’
struct __attribute__ ((may_alias)) alignas (2)
^~~~~~~
v.c:20:36: warning: attribute ignored [-Wattributes]
v.c:20:36: note: an attribute that appertains to a type-specifier is ignored
More information about the Gcc-bugs
mailing list