[Clang] rejects valid attribute-specifier in elaborated-type-specifier
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.
@llvm/issue-subscribers-clang-frontend
Author: None (YuchangSu)
Code:
using X1 = class [ [ ] ] X0 ;
See Compiler Explorer: https://godbolt.org/z/EdfTTe6MG
The test case was generated by a fuzzer.
[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.
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.
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.