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

Kashika Akhouri via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 10 01:40:45 PDT 2026


kashika0112 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.cpp 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.

Thanks for providing this. I have updated the `handleLifetimeCaptureBy` function to use `isPointerLikeType` instead of `isGslPointerType`.

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


More information about the cfe-commits mailing list