[clang] [clang-tools-extra] [clang] Retain unrecognized C++ [[attributes]] in the AST (PR #209224)
Vassil Vassilev via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 23 02:09:37 PDT 2026
vgvassilev wrote:
Thanks @mizvekov and @erichkeane. I verified this against the patch and it matches Erich's point.
For a genuinely unknown attribute the arguments are retained as verbatim source text and are never parsed, substituted, or checked, so a dependent argument stays as written through instantiation:
```cpp
template <class T> struct D { int y [[vendor::attr(T::value + 1)]]; };
struct NoValue {};
template struct D<NoValue>; // ok, no error
```
The specialization keeps "(T::value + 1)", and instantiating with a type lacking value is not an error, because [dcl.attr.grammar]/8 ignores the unrecognized attribute, so there is nothing to substitute or diagnose.
The `[[gnu::section(T::value)]]` case is a recognized attribute that is misapplied, and the patch deliberately doesn't touch those — they keep their own handler, substitution, and SFINAE behavior. Only genuinely unrecognized attributes are retained, so this doesn't change dependent-argument behavior for any known attribute. Requiring the args to be parsable (so they could be substituted) isn't possible for an attribute whose grammar we don't know, which is the whole reason the payload is text.
Added a template test pinning both behaviors, and I'll note the verbatim-not-substituted rule in the RFC as a defined limitation of the opaque-text representation.
https://github.com/llvm/llvm-project/pull/209224
More information about the cfe-commits
mailing list