[clang] Support [[clang::lifetime_capture_by(X)]] in Plain Containers (PR #204361)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 21 04:37:54 PDT 2026


usx95 wrote:

> The false-positives look much better now.
> 
> I think the `vector_of_pointer` is still quite problematic.

​I figured the following would fix it:
```diff
diff --git a/clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp b/clang/lib/Analysis/LifetimeSafety/FactsGenerator.c
pp
index 3f1d9842f951..32795e6dfa4f 100644
--- a/clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp
+++ b/clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp
@@ -919,7 +919,7 @@ void FactsGenerator::handleLifetimeCaptureBy(const FunctionDecl *FD,
       continue;
     if (QualType ParamType = PVD->getType();
         ParamType->isReferenceType() &&
-        isGslPointerType(ParamType->getPointeeType())) {
+        isPointerLikeType(ParamType->getPointeeType())) {
       if (CapturedOriginList->getLength() > 1) {
         CapturedOriginList = CapturedOriginList->peelOuterOrigin();
       }
```
This is because we have reference to pointers and we need to peel an origin same as reference to view types.

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


More information about the cfe-commits mailing list