[clang] [LifetimeSafety] Add suggestion and inference for implicit this (PR #176703)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 23 08:56:45 PST 2026


================
@@ -14735,6 +14735,24 @@ StmtResult Sema::ActOnCXXForRangeIdentifier(Scope *S, SourceLocation IdentLoc,
                                                       : IdentLoc);
 }
 
+void Sema::addLifetimeBoundToImplicitThis(const CXXMethodDecl *MD) {
+  CXXMethodDecl *MutableMD = const_cast<CXXMethodDecl *>(MD);
+  if (lifetimes::implicitObjectParamIsLifetimeBound(MutableMD))
+    return;
+  auto *Attr =
+      LifetimeBoundAttr::CreateImplicit(Context, MutableMD->getLocation());
+  QualType MethodType = MutableMD->getType();
+  QualType AttributedType =
+      Context.getAttributedType(attr::LifetimeBound, MethodType, MethodType);
----------------
usx95 wrote:

nit: use `ASTContext::getAttributedType(const Attr *attr, QualType modifiedType,QualType equivalentType)` and pass `Attr` to it.

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


More information about the cfe-commits mailing list