Hi Utkarsh,
I also tested another footgun, namely lambda-captures with a coroutine lambda. Your analysis does not yet detect the buggy pattern below:
int z = 10;
auto k = [z]() -> co_future<int> {
using namespace std::chrono_literals;
co_await seastar::sleep(1s);
co_return z;
}();
auto z_is_garbage = co_await std::move(k);
Here, the lambda object (including its captures) is already dead after the first co_await, so the capture z will be garbage when it is returned.
One possible fix is to store the lambda itself in the coroutine frame (before invoking)
int z = 10;
auto lamb = [z]() -> co_future<int> {
using namespace std::chrono_literals;
co_await seastar::sleep(1s);
co_return z;
};
auto k = lamb();
auto equal_to_z = co_await std::move(k);
Would you see any way to extend your lifetime analysis so that it can detect this footgun pattern with coroutine-lambdas ?