[clang] [LifetimeSafety] Suggest lifetime annotations (PR #169767)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 28 00:37:17 PST 2025


================
@@ -2884,6 +2884,17 @@ class LifetimeSafetyReporterImpl : public LifetimeSafetyReporter {
         << EscapeExpr->getEndLoc();
   }
 
+  void reportMissingAnnotations(const ParmVarDecl *PVD,
+                                const Expr *EscapeExpr) override {
+    S.Diag(PVD->getLocation(),
+           diag::warn_lifetime_param_should_be_lifetimebound)
+        << PVD->getSourceRange()
+        << FixItHint::CreateInsertion(
+               PVD->getTypeSourceInfo()->getTypeLoc().getBeginLoc(),
----------------
usx95 wrote:

This looks suspicious. We should insert the lifetimebound after the parameter and not after the parameter type.

`int* identity(int* a [[clang::lifetimebound]]);`​

and not `int* identity(int* [[clang::lifetimebound]] a);`​

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


More information about the cfe-commits mailing list