https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110734
Bug ID: 110734
Summary: Attributes cannot be applied to asm statements
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: tanksherman27 at gmail dot com
Target Milestone: ---
Consider the following:
[[gnu::no_reorder]]
asm ("nop");
The correct gcc warning should be that "attributes in front of statements
are ignored", signifying that the asm was correctly processed as a
statement, and the attribute dropped during that processing, but instead:
error.cpp:51:5: error: expected primary-expression before 'asm'
51 | asm ("nop" "\n\t"
| ^~~
error.cpp:50:5: warning: attributes at the beginning of statement are
ignored [-Wattributes]
50 | [[gnu::no_reorder]]
| ^~~~~~~~~~~~~~~~~~~
The compiler errors out, with the parser strangely having expected an
expression after the attribute. Afterwards, it then confusingly parses the
asm statement and discards the attribute correctly, so I am fairly certain
this is a bug. The attribute above may not be a very good example, but
there are attributes like gnu::hot and gnu::cold which are supposed to work
with asm statements.