[clang] [LifetimeSafety] Fix assertion failure inferring lifetimebound 'this' for deduced return types (PR #233558)

via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 20 08:53:12 PDT 2026


=?utf-8?q?Balázs?= Benics <benicsbalazs at gmail.com>,
=?utf-8?q?Balázs?= Benics <benicsbalazs at gmail.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/233558 at github.com>


================
@@ -15128,8 +15128,18 @@ void Sema::addLifetimeBoundToImplicitThis(CXXMethodDecl *MD) {
   QualType AttributedType =
       Context.getAttributedType(Attr, MethodType, MethodType);
   TypeLocBuilder TLB;
-  if (TypeSourceInfo *TSI = MD->getTypeSourceInfo())
+  TypeSourceInfo *TSI = MD->getTypeSourceInfo();
+  if (TSI && TSI->getTypeLoc().getType() == MethodType) {
     TLB.pushFullCopy(TSI->getTypeLoc());
+  } else {
+    // The written type-source info can disagree with the method's type. For
+    // example, a deduced 'auto' return type in a template instantiation keeps
----------------
NeKon69 wrote:

Yeah, would be nice!

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


More information about the cfe-commits mailing list