[clang] [LifetimeSafety] Add fix-it for misplaced lifetimebound attributes (PR #199149)
via cfe-commits
cfe-commits at lists.llvm.org
Fri May 22 01:36:45 PDT 2026
================
@@ -297,9 +297,25 @@ class LifetimeSafetySemaHelperImpl : public LifetimeSafetySemaHelper {
Scope == WarningScope::CrossTU
? diag::warn_lifetime_safety_cross_tu_misplaced_lifetimebound
: diag::warn_lifetime_safety_intra_tu_misplaced_lifetimebound;
- S.Diag(Lexer::getLocForEndOfToken(FDecl->getEndLoc(), 0,
- S.getSourceManager(), S.getLangOpts()),
- DiagID);
+
+ SourceLocation DiagLoc = Lexer::getLocForEndOfToken(
+ FDecl->getEndLoc(), 0, S.getSourceManager(), S.getLangOpts());
+
+ // Scope so diagnostic emits first.
+ {
+ auto DB = S.Diag(DiagLoc, DiagID);
+
+ SourceLocation FixItLoc;
+ if (const TypeSourceInfo *TSI = FDecl->getTypeSourceInfo())
+ FixItLoc =
+ Lexer::getLocForEndOfToken(TSI->getTypeLoc().getEndLoc(), 0,
+ S.getSourceManager(), S.getLangOpts());
+ else
+ FixItLoc = DiagLoc;
+
+ if (FixItLoc.isValid() && !FixItLoc.isMacroID())
+ DB << FixItHint::CreateInsertion(FixItLoc, " [[clang::lifetimebound]]");
+ }
----------------
NeKon69 wrote:
We probably want the fix it to be placed after the diagnostic is emitted same as for the other suggestions.
https://github.com/llvm/llvm-project/pull/199149
More information about the cfe-commits
mailing list