[clang] [Clang] add fix-it hints for unknown attributes (PR #141305)
Oleksandr T. via cfe-commits
cfe-commits at lists.llvm.org
Tue May 27 07:15:26 PDT 2025
================
@@ -7867,15 +7867,16 @@ void Sema::checkUnusedDeclAttributes(Declarator &D) {
void Sema::DiagnoseUnknownAttribute(const ParsedAttr &AL) {
std::string NormalizedFullName = '\'' + AL.getNormalizedFullName() + '\'';
+ SourceRange NR = AL.getNormalizedRange();
+ SourceLocation Loc = NR.getBegin();
+
if (auto CorrectedFullName =
AL.getCorrectedFullName(Context.getTargetInfo(), getLangOpts())) {
- Diag(AL.getNormalizedRange().getBegin(),
- diag::warn_unknown_attribute_ignored_suggestion)
- << NormalizedFullName << *CorrectedFullName << AL.getNormalizedRange();
+ Diag(Loc, diag::warn_unknown_attribute_ignored_suggestion)
+ << NormalizedFullName << *CorrectedFullName
+ << FixItHint::CreateReplacement(NR, *CorrectedFullName) << NR;
} else {
- Diag(AL.getNormalizedRange().getBegin(),
- diag::warn_unknown_attribute_ignored)
- << NormalizedFullName << AL.getNormalizedRange();
+ Diag(Loc, diag::warn_unknown_attribute_ignored) << NormalizedFullName << NR;
----------------
a-tarasyuk wrote:
@AaronBallman, thanks for the feedback. I replaced diag::warn_unknown_attribute_ignored with `DiagnoseUnknownAttribute` for known cases. Since this general message is used in many places, it might be worth reviewing all cases to see where it would be appropriate to use `DiagnoseUnknownAttribute` instead. If any additinal cases should be covered, I’d appreciate it if you could point them out — I’ll be happy to investigate., thanks.
https://github.com/llvm/llvm-project/pull/141305
More information about the cfe-commits
mailing list