| Issue |
76995
|
| Summary |
[[coro_lifetimebound]] does not catch lifetime issues with lambda captures
|
| Labels |
new issue
|
| Assignees |
usx95
|
| Reporter |
usx95
|
The pattern of interest is
```cpp
co_task<int> coro() {
int a = 1;
auto lamb = [a](int x, const int& y) -> co_task<int> {
co_return x + y + a; // 'a' in the lambda object dies after the iniital_suspend.
}(1, a);
co_return co_await lamb;
}
```
https://godbolt.org/z/GWPEovWWc
Lambda captures (even by value) are prone to use after free once the lambda object dies. In the above example, it appears only as a temporary in the call _expression_.
It should be fine if this is used in a `co_await` _expression_. Example:
```cpp
co_task<int> coro() {
int a = 1;
int res = co_await [a](int x, const int& y) -> co_task<int> {
co_return x + y + a;
}(1, a);
co_return res;
}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs