[clang-tools-extra] [clang-tidy] Add bugprone-lambda-capture-lifetime check (PR #203757)

Baranov Victor via cfe-commits cfe-commits at lists.llvm.org
Sun Jun 14 10:29:33 PDT 2026


vbvictor wrote:

> > I feel this should be part of [lifetime safety analysis](https://clang.llvm.org/docs/LifetimeSafety.html), but it currently don't model lambda captures/threads I think?
> 
> We do model lambda captures: https://godbolt.org/z/9Y7PYcfsf, but yes, threads we do not model yet. Though it definitely would be nice to have! (But I don't think we have any open issues regarding that)

Oh, thank you for clarification! As I see it doesn't support "deeper" indirections when using `std::vector<std::function>`, like this: https://godbolt.org/z/Kvr9xKdcE. Single escapes through single variable works just fine.

With that said, I think modeling of `std::thread` will solve half of the logic of this check. The other half could be addressed by modeling "`std::vector<Fun>`" escape paths.

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


More information about the cfe-commits mailing list