[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:39:57 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:

> That said, we COULD fixit just the identifier where it is, right? 

1. `[[deprecatd]]`      - fixit
2. `[[gmp::deprecatd]]` - we could provide a `fix-it`, but since there's no difference between `::` and a scope introduced via `using`, it might lead to incorrect suggestions in `using` cases.
3. `[[using gmp: deprecatd, noreturn]]` - not ok, because fixit will be `gnu::deprecated`

> Since we already know the scope and are correcting within the scope, we can't just change the current 'identifier' to what we're suggesting as a fixit? IF we limited it that way, it would 'inherit' whatever sort of scoping was already there perhaps?

What I was thinking is that if we have information about the `attribute-using prefix`, we could avoid normalization when suggesting a typo correction (while still using the scope::attr format in the diagnostic message). Instead, we could provide two separate fix-its: one for the scope and one for the attribute name. Not sure if that approach makes sense.



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


More information about the cfe-commits mailing list