boostorg / cobalt

Coroutines for C++20 & asio
https://www.boost.org/doc/libs/master/libs/cobalt/doc/html/index.html
207 stars 24 forks source link

co_return in cobalt::thread: cobalt::thread has no member return_value #155

Closed kilasuelika closed 8 months ago

kilasuelika commented 8 months ago

Following code:

#include <boost/cobalt.hpp>
#include <boost/asio/steady_timer.hpp>
using namespace boost;
cobalt::thread my_thread()
{
    auto exec = co_await cobalt::this_coro::executor;
    asio::steady_timer tim{ exec, std::chrono::milliseconds(50) };
    co_await tim.async_wait(cobalt::use_op);
    co_return 0;
}

int main(int argc, char* argv[])
{
    auto thr = my_thread();
    thr.join();
    return 0;
}

is from official documentation: cobalt::thread. But it failed to compile in VS 2022 with latest standard:

1>D:\C++\test_cobalt\test_cobalt\test_cobalt.cpp(9,5): error C2039: 'return_value': is not a member of 'boost::cobalt::detail::thread_promise'

The error happens on the the line co_return 0.

klemens-morgenstern commented 8 months ago

That would be a mistake in the docs. cobalt::thread should co_return void, not a value.

kilasuelika commented 8 months ago

That would be a mistake in the docs. cobalt::thread should co_return void, not a value.

That's right. Thank you!