public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108643] New: Initializing parameter by ref in coroutine function causes memory corruption
@ 2023-02-02 17:01 menkaur at gmail dot com
  0 siblings, 0 replies; only message in thread
From: menkaur at gmail dot com @ 2023-02-02 17:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108643

            Bug ID: 108643
           Summary: Initializing parameter by ref in coroutine function
                    causes memory corruption
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: menkaur at gmail dot com
  Target Milestone: ---

Created attachment 54392
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54392&action=edit
example code

I'm using libcoro (https://github.com/jbaldwin/libcoro) for generator class, on
my system it's compiled and installed

To reproduce bug, you have to write coroutine as follows:

coro::generator<const int> vector_to_generator(const std::vector<int> &test)
{
    for (auto &i : test)
    {
        co_yield i;
    }
}

test method looks like this:
coro::generator<const int> test(coro::generator<const int> source, const
std::string &prompt)
{
    for (auto &i : source)
    {
        std::cout << prompt << i << std::endl;
        co_yield i;
    }
}



if we initialize test with initializer list instead of another object, this
will result in memory corruption:

for (auto &i : test(vector_to_generator({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}),
"test:"))
{
}

expected output:

test:1671954983
test:5
test:-724690709
test:621133568
test:5
test:6
test:7
test:8
test:9
test:10

(or segfault, which is how I found it)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-02 17:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-02 17:01 [Bug c++/108643] New: Initializing parameter by ref in coroutine function causes memory corruption menkaur at gmail dot com

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).