[Bug c++/88086] New: gcc only allows valid expressions as unknown C++ attribute argument clause
bruno-gcc at defraine dot net
gcc-bugzilla@gcc.gnu.org
Mon Nov 19 10:34:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88086
Bug ID: 88086
Summary: gcc only allows valid expressions as unknown C++
attribute argument clause
Product: gcc
Version: 8.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: bruno-gcc at defraine dot net
Target Milestone: ---
GCC raises an error when the argument of an (unknown) C++ attribute contains an
undeclared identifier. Tested with -std=c++17:
int i [[vendor::attr(somename)]];
// error: 'somename' was not declared in this scope
More in general, GCC seem to expect a valid expression as the argument:
int i [[vendor::attr(123?456)]];
// error: expected ':' before ')' token
// error: expected primary-expression before ')' token
Similarly, a specific example listed as "well-formed implementation-defined
attribute" in the standard also raises errors in GCC:
int i [[vendor::attr([[]])]]; // well-formed implementation-defined attribute
// error: expected identifier before '[' token
// In lambda function:
// error: expected '{' before ')' token
The treatment by GCC of the attribute argument as an expression does not seem
in line with the C++ standard (section 10.6.1 Attribute syntax and semantics),
which defines the attribute argument as any balanced token sequence, and which
also specifies that "any attribute-token that is not recognized by the
implementation is ignored". From this, you would expect a conforming compiler
to skip the balanced tokens in the argument of an unknown attribute.
This also seems to be what other compilers (clang, MSVC,...) are doing.
More information about the Gcc-bugs
mailing list