Issue |
81472
|
Summary |
alignas attribute not recognized in specifier-qualifier position of a member declaration
|
Labels |
new issue
|
Assignees |
|
Reporter |
bhaible
|
The following C program
```
#include <stdalign.h>
struct alignas_test { char c; char alignas (8) alignas_8; };
```
gives a compilation error when compiled by `clang -std=gnu2x`. The clang version is 17.0.4.
How to reproduce:
```
$ cat foo.c
#include <stdalign.h>
struct alignas_test { char c; char alignas (8) alignas_8; };
$ clang -std=gnu2x -c foo.c
foo.c:2:36: error: 'alignas' attribute cannot be applied to types
2 | struct alignas_test { char c; char alignas (8) alignas_8; };
| ^
1 error generated.
```
The `alignas (8)` attribute is accepted when moved after the member name (i.e. right before the semicolon), but that is not where ISO C 23 wants to see it. Quoting ISO C 23 § 6.7.5 paragraph 2:
"An alignment specifier shall appear only
- in the declaration specifiers of a declaration, or
- in the specifier-qualifier list of a member declaration, or
- in the type name of a compound literal.
An alignment specifier shall not be used in conjunction with
- either of the storage-class specifiers typedef or register, nor
- in a declaration of a function or bit-field."
According to the definitions of `member-declaration` and `specifier-qualifier-list` in ISO C 23 § 6.7.2.1, in the code above, `alignas (8)` is part of a `specifier-qualifier`; therefore it is valid.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs