[clang] [clang][Sema] Deprecate `global`/`unknown` in `lifetime_capture_by` (PR #196635)

via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 8 10:57:38 PDT 2026


================
@@ -4426,6 +4450,17 @@ LifetimeCaptureByAttr *Sema::ParseLifetimeCaptureByAttr(const ParsedAttr &AL,
     }
     assert(AL.isArgIdent(I));
     IdentifierLoc *IdLoc = AL.getArgAsIdent(I);
+    StringRef Name = IdLoc->getIdentifierInfo()->getName();
+    StringRef Replacement;
+    if (Name == "this")
+      Replacement = "lifetime_capture_by_this";
+    else if (Name == "global")
+      Replacement = "lifetime_capture_by_global";
+    else if (Name == "unknown")
+      Replacement = "lifetime_capture_by_unknown";
+    if (!Replacement.empty())
+      Diag(IdLoc->getLoc(), diag::warn_deprecated_capture_by_special_entity)
----------------
NeKon69 wrote:

I might be a little confused, I though the idea was that we will not allow `unknown`/`global`/`this` in `lifetime_capture_by` (we deprecate them now), is that not the case ?

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


More information about the cfe-commits mailing list