public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/100850] New: [coroutine] Wrong addresses of variables captured by reference into lambda co-routines.
@ 2021-06-01  8:37 vsolontsov at volanttrading dot com
  2021-06-01  8:39 ` [Bug c++/100850] " vsolontsov at volanttrading dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: vsolontsov at volanttrading dot com @ 2021-06-01  8:37 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-06-02 10:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-01  8:37 [Bug c++/100850] New: [coroutine] Wrong addresses of variables captured by reference into lambda co-routines vsolontsov at volanttrading dot com
2021-06-01  8:39 ` [Bug c++/100850] " vsolontsov at volanttrading dot com
2021-06-01  8:41 ` vsolontsov at volanttrading dot com
2021-06-01 16:18 ` vsolontsov at volanttrading dot com
2021-06-02  9:51 ` iains at gcc dot gnu.org
2021-06-02 10:14 ` vsolontsov at volanttrading dot com
2021-06-02 10:20 ` iains at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).