6

I tried to create an application using stackless C++20 coroutines and asio (without boost). Therefore I am using the MSVC Compiler. The following code snippet can be compiled with the /await flag:

#include <asio.hpp>
int main(){
    asio::io_context ioContext(1);
    asio::co_spawn(ioContext.get_executor(), []() -> asio::awaitable<void> { return {}; }, asio::detached);
    return 0;
}

As soon as I add the compiler flag /std:c++latest, the code does not compile anymore. I get an error instead:

...\_libs\asio-1.16.1\include\asio\async_result.hpp(289,1): error C7602: 'asio::async_result': the associated constraints are not satisfied (compiling source file main.cpp)
...\_libs\asio-1.16.1\include\asio\async_result.hpp(107): message : see declaration of 'asio::async_result' (compiling source file main.cpp)
...\_libs\asio-1.16.1\include\asio\impl\co_spawn.hpp(139): message : see reference to class template instantiation 'asio::detail::async_result_has_initiate_memfn<CompletionToken,asio::detail::awaitable_signature<asio::awaitable<void,asio::executor>>>' being compiled
        with
        [
            CompletionToken=const asio::detached_t &
        ] (compiling source file main.cpp)
...\main.cpp(4): message : see reference to function template instantiation 'auto asio::co_spawn<asio::io_context::executor_type,main::<lambda_1>,const asio::detached_t&>(const Executor &,F &&,CompletionToken,void *)' being compiled
        with
        [
            Executor=asio::io_context::executor_type,
            F=main::<lambda_1>,
            CompletionToken=const asio::detached_t &
        ]
...\_libs\asio-1.16.1\include\asio\async_result.hpp(288,36): error C2672: 'asio::detail::async_result_initiate_memfn_helper': no matching overloaded function found (compiling source file main.cpp)
...\_libs\asio-1.16.1\include\asio\async_result.hpp(290,1): error C3206: 'asio::detail::async_result_initiate_memfn_helper': invalid template argument for 'T', missing template argument list on class template 'asio::async_result' (compiling source file main.cpp)
...\_libs\asio-1.16.1\include\asio\async_result.hpp(281): message : see declaration of 'asio::detail::async_result_initiate_memfn_helper' (compiling source file main.cpp)

How can I make use of the latest C++ features and standalone asio coroutine functionality? Am I doing something wrong? Is there something I forgot?

CHF
  • 264
  • 4
  • 17
  • I'm having the same error when trying to compile the official C++17 echo server example with visual studio 19. `/await` and `BOOST_ASIO_HAS_CO_AWAIT` are set :-( – Marti Nito Jun 22 '20 at 20:37
  • One mistake of mine was defining `BOOST_ASIO_HAS_CO_AWAIT ` instead of `ASIO_HAS_CO_AWAIT `! But it still doesnt work :-/ – Marti Nito Jun 22 '20 at 20:57
  • It's working now. Could be a compiler bug. I defined BOOST_ASIO_HAS_STD_COROUTINE and BOOST_ASIO_HAS_CO_AWAIT – pratikpc Dec 23 '20 at 15:51

0 Answers0