llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[Clang] rejects valid attribute-specifier in elaborated-type-specifier

Open YuchangSu opened this issue 9 months ago • 4 comments

The code uses an attribute-specifier-seq after a class-key in an elaborated type in a type-alias declaration. GCC accepts it, but Clang rejects it.

Code:

using X1 = class [ [ ] ] X0 ;

See Compiler Explorer: https://godbolt.org/z/EdfTTe6MG

The test case was generated by a fuzzer.

YuchangSu avatar Feb 26 '26 09:02 YuchangSu

@llvm/issue-subscribers-clang-frontend

Author: None (YuchangSu)

The code uses an attribute-specifier-seq after a class-key in an elaborated type in a type-alias declaration. GCC accepts it, but Clang rejects it.

Code:

using X1 = class [ [ ] ] X0 ;

See Compiler Explorer: https://godbolt.org/z/EdfTTe6MG

The test case was generated by a fuzzer.

llvmbot avatar Feb 26 '26 12:02 llvmbot

[dcl.type.elab]/2: "If an elaborated-type-specifier is the sole constituent of a declaration, [...] the attribute-specifier-seq, if any, appertains to the class or template being declared." [dcl.type.elab]/3: "Otherwise, an elaborated-type-specifier E shall not have an attribute-specifier-seq."

So Clang is right. An attribute specifier is not valid as part of an elaborated type specifier except when it's the sole constituent of a declaration.

zygoloid avatar Feb 26 '26 20:02 zygoloid

For what it's worth, the GCC issue here appears to apply only to empty attribute-specifiers; it properly diagnoses (with a warning) if any attributes are actually specified.

zygoloid avatar Feb 26 '26 20:02 zygoloid

Note clang behavior is kind of interesting too. Take:

using X1 = class [[unknown::unknown]] X0 ;

clang accepts this with just a warning about an unknown attribute. But if the attribute is know, clang rejects it.

pinskia avatar Feb 27 '26 07:02 pinskia