llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[LifetimeSafety] False-positive invalidation with lambda capturing a container

Open usx95 opened this issue 8 months ago • 3 comments

#include <iostream>
#include <vector>

void foo() {
    std::vector<int> v;
    auto print = [&]() { std::cout << v.size(); };
    v.push_back(0);
    print();
}

This is because we currently consider even the reference to v (which is captured by the lambda) as invalidated after the push_back. We need granular paths to represent interior invalidations.

usx95 avatar Mar 17 '26 11:03 usx95

@llvm/issue-subscribers-clang-temporal-safety

Author: Utkarsh Saxena (usx95)

```cpp #include <iostream> #include <vector>

void foo() { std::vector<int> v; auto print = & { std::cout << v.size(); }; v.push_back(0); print(); }


This is because we currently consider even the reference to `v` (which is captured by the lambda) as invalidated after the `push_back`. We need granular paths to represent interior invalidations.
</details>

llvmbot avatar Mar 17 '26 11:03 llvmbot

Hey @usx95 , I am interested in this issue, can u assign this to me ?

iitianpushkar avatar Jul 11 '26 06:07 iitianpushkar

Gentle ping @usx95 for assigning this to me.

iitianpushkar avatar Sep 25 '26 05:09 iitianpushkar