Boost logo

Boost Users :

From: Piotr Gosławski (goslawski.p_at_[hidden])
Date: 2022-08-23 07:43:16


Using GCC 10.1 and Boost 1.77 I get a mem fault when executing the
following code:

#include <iostream>
#include <boost/asio.hpp>
#include <boost/asio/awaitable.hpp>

struct TestStruct {
std::string strField;

boost::asio::awaitable<bool> TestFunction(TestStruct param) {
std::cout << param.strField << std::endl;
co_return true;

boost::asio::awaitable<void> TestCoroutine() {
// This causes mem issue
co_await TestFunction(TestStruct{"some string"});

int main()
boost::asio::io_context io_context;

[]() { return TestCoroutine(); },
return 0;
} Also tested with GCC 12.1 and Boost 1.79 - the result is the same (

Works if I use a temp variable:
boost::asio::awaitable<void> TestCoroutine() {
auto testStruct = TestStruct{"some string"};
co_await TestFunction(testStruct);
Or if I add a constructor to test struct:

struct TestStruct {
    explicit TestStruct(const std::string& str) : strField(str) {}
    std::string strField;

boost::asio::awaitable<void> TestCoroutine() {
    co_await TestFunction(TestStruct("some string"));

Is there any coroutines rule that I am violating here? If yes - is there
any compiler option I can use to get a warning / error message?

Full code with cmake can be found here:

Thank you

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at