https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100850
Bug ID: 100850
Summary: [coroutine] Wrong addresses of variables captured by
reference into lambda co-routines.
Product: gcc
Version: 11.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: vsolontsov at volanttrading dot com
Target Milestone: ---
In a code like this:
```
int i;
auto coro = [&i, pi = &i](int& i1) -> task {
// co_await std::suspend_always{};
std::cout << "&i==&i1: " << std::boolalpha << (&i == &i1) << std::endl;
std::cout << "&i==pi: " << std::boolalpha << (&i == pi) << std::endl;
std::cout << "&i1==pi: " << std::boolalpha << (&i1 == pi) << std::endl;
co_return;
}(i);
```
If the captured variables are not used until the very first suspension, the
addresses appear to be wrong. https://godbolt.org/z/c945q893j
If the `task::initial_suspend()` returns `suspend_never` and the `co_await` in
the co-routine is commented out, all good. Otherwise, if there's a suspension
before the first use of the variables, the address get screwed.