chriskohlhoff / asio

Asio C++ Library
http://think-async.com/Asio
4.85k stars 1.21k forks source link

co_await deferred awaitable operation returning non-void fails to compile #1205

Open gummif opened 1 year ago

gummif commented 1 year ago

With

awaitable<int> f()
{
    co_return 42;
}
awaitable<void> g()
{
    co_return;
}

Awaiting f fails to compile but g is fine.

co_await co_spawn(ioc, f(), deferred); // Error
co_await co_spawn(ioc, g(), deferred); // OK

With error

In file included from /opt/compiler-explorer/libs/boost_1_81_0/boost/asio/awaitable.hpp:140,
                 from /opt/compiler-explorer/libs/boost_1_81_0/boost/asio/use_awaitable.hpp:22,
                 from <source>:3:
/opt/compiler-explorer/libs/boost_1_81_0/boost/asio/impl/awaitable.hpp: In instantiation of 'static T boost::asio::detail::awaitable_async_op_handler<R(std::__exception_ptr::exception_ptr, T), Executor>::resume(result_type&) [with R = void; T = int; Executor = boost::asio::any_io_executor]':
/opt/compiler-explorer/libs/boost_1_81_0/boost/asio/impl/awaitable.hpp:1114:32:   required from 'auto boost::asio::detail::awaitable_async_op< <template-parameter-1-1>, <template-parameter-1-2>, <template-parameter-1-3> >::await_resume() [with Signature = void(std::__exception_ptr::exception_ptr, int); Op = boost::asio::deferred_async_operation<void(std::__exception_ptr::exception_ptr, int), boost::asio::detail::initiate_co_spawn<boost::asio::any_io_executor>, boost::asio::detail::awaitable_as_function<int, boost::asio::any_io_executor> >; Executor = boost::asio::any_io_executor]'
<source>:32:49:   required from here
/opt/compiler-explorer/libs/boost_1_81_0/boost/asio/impl/awaitable.hpp:956:9: error: no match for 'operator*' (operand type is 'boost::asio::detail::awaitable_async_op_handler<void(std::__exception_ptr::exception_ptr, int), boost::asio::any_io_executor>::result_type')
  956 |     if (*result)