[clang] [Clang] add fix-it hints for unknown attributes (PR #141305)

Oleksandr T. via cfe-commits cfe-commits at lists.llvm.org
Wed May 28 13:05:41 PDT 2025


================
@@ -7867,15 +7865,16 @@ void Sema::checkUnusedDeclAttributes(Declarator &D) {
 
 void Sema::DiagnoseUnknownAttribute(const ParsedAttr &AL) {
   std::string NormalizedFullName = '\'' + AL.getNormalizedFullName() + '\'';
+  SourceRange NR = AL.getNormalizedRange();
----------------
a-tarasyuk wrote:

> AND having it set the Attribute as invalid would be valuable.
> Could we change this to take AttributeCommonInfo instead? Or is there something that we need the full ParsedAttr for?

@erichkeane Thanks for the feedback. In general, it’s possible to use `AttributeCommonInfo`, but I used `ParsedAttr` because all existing cases that handle unknown attributes rely on `ParsedAttr`. If we switch to `AttributeCommonInfo`, we lose the ability to mark the attribute as invalid, since `setIsInvalid` is only available on `ParsedAttr`.

---

@erichkeane we've a discussion about this case with @AaronBallman. Unless we plan a broader refactoring to properly support attribute groups, would it make sense to provide `fixit` only when there is no scope?

```cpp
[deprecatd] // fix-it
```

To handle cases involving `using` correctly, it's necessary to at least preserve whether the scope was part of an `attribute-using-prefix`. WDYT?







https://github.com/llvm/llvm-project/pull/141305


More information about the cfe-commits mailing list