public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "hodges.r at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/107288] Double-free of temporaries created in statement following co_await
Date: Tue, 18 Oct 2022 10:47:49 +0000	[thread overview]
Message-ID: <bug-107288-4-9EgxIGGq9X@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-107288-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #2 from Richard Hodges <hodges.r at gmail dot com> ---
Some extra diagnostic. Reducing to this minimal program:

```
#include <boost/asio/awaitable.hpp>
#include <boost/asio/co_spawn.hpp>
#include <boost/asio/detached.hpp>
#include <boost/asio/io_context.hpp>

namespace asio = boost::asio;

struct foo
{
    std::string s;
    int         i;
};

struct bar : foo
{
    bar(std::string s, int i)
    : foo { .s = std::move(s), .i = i }
    {
    }
};

asio::awaitable< void >
co_foo(foo)
{
    std::printf("%s\n", __func__);
    co_return;
};

asio::awaitable< void >
co_bar(foo)
{
    std::printf("%s\n", __func__);
    co_return;
};

asio::awaitable< void >
co_test()
{
    // this works
    co_await co_bar(bar("Hello, World!", 1));
    // this works but this crashes
    co_await co_foo({ .s = "Hello, World!", .i = 1 });
}

int
main()
{
    asio::io_context ioc;
    asio::co_spawn(ioc, co_test(), asio::detached);
    ioc.run();
}
```

Output:
```
co_bar
co_foo
Segmentation fault (core dumped)
```

So it seems related to the interplay between designated initialisers and
coroutines.

  parent reply	other threads:[~2022-10-18 10:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-17  8:31 [Bug c++/107288] New: " hodges.r at gmail dot com
2022-10-17  8:36 ` [Bug c++/107288] " hodges.r at gmail dot com
2022-10-17 12:01 ` marxin at gcc dot gnu.org
2022-10-18 10:47 ` hodges.r at gmail dot com [this message]
2023-04-22 19:40 ` [Bug c++/107288] coroutines: " StevenSun2021 at hotmail dot com
2024-05-06  6:25 ` accelerator0099 at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-107288-4-9EgxIGGq9X@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).