https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101682
Bug ID: 101682
Summary: gcc incorrectly rejects C2x attributes after
declaration-specifiers
Product: gcc
Version: 11.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: eggert at gnu dot org
Target Milestone: ---
The grammar at the start of section 6.7 of the current C2x draft (N2596) says
that attribute specifiers may appear either before or after declaration
specifiers. Unfortunately, GCC rejects attribution specifiers after declaration
specifiers. For example, for this this source code:
extern [[nodiscard]] int f (void);
extern int [[nodiscard]] g (void);
int [[nodiscard]] h (void);
[[nodiscard]] extern int i (void);
[[nodiscard]] int j (void);
the command 'gcc -S t.c' rejects the first three lines even though they conform
to the draft standard. It allows only the last two lines. The incorrect GCC
output is:
t.c:1:1: warning: ‘nodiscard’ attribute ignored [-Wattributes]
1 | extern [[nodiscard]] int f (void);
| ^~~~~~
t.c:1:22: error: expected identifier or ‘(’ before ‘int’
1 | extern [[nodiscard]] int f (void);
| ^~~
t.c:2:1: warning: ‘nodiscard’ attribute ignored [-Wattributes]
2 | extern int [[nodiscard]] g (void);
| ^~~~~~
t.c:3:1: warning: ‘nodiscard’ attribute ignored [-Wattributes]
3 | int [[nodiscard]] h (void);
| ^~~
This is with GCC 11.2.0, which I built myself on an RHEL 8.4 x86-64 platform.