chriskohlhoff / asio

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

Compile error occurs when creating an `executor_work_guard` from `strand<any_io_executor>` #1394

Open ashtum opened 6 months ago

ashtum commented 6 months ago

It seems wrapping any_io_executor in a strand causes the selection of the wrong specialization of executor_work_guard.

https://godbolt.org/z/o1r8WhTPE

#include <boost/asio.hpp>

namespace asio = boost::asio;

int main()
{
    asio::io_context ioc;
    asio::any_io_executor exec = ioc.get_executor();
    auto strand = asio::make_strand(exec);
    auto wg = asio::make_work_guard(strand);
}
In file included from <source>:1:
In file included from /opt/compiler-explorer/libs/boost_1_83_0/boost/asio.hpp:188:
/opt/compiler-explorer/libs/boost_1_83_0/boost/asio/strand.hpp:251:15: error: no member named 'on_work_started' in 'boost::asio::any_io_executor'
  251 |     executor_.on_work_started();
      |     ~~~~~~~~~ ^
/opt/compiler-explorer/libs/boost_1_83_0/boost/asio/executor_work_guard.hpp:101:15: note: in instantiation of member function 'boost::asio::strand<boost::asio::any_io_executor>::on_work_started' requested here
  101 |     executor_.on_work_started();
      |               ^
/opt/compiler-explorer/libs/boost_1_83_0/boost/asio/executor_work_guard.hpp:260:10: note: in instantiation of member function 'boost::asio::executor_work_guard<boost::asio::strand<boost::asio::any_io_executor>>::executor_work_guard' requested here
  260 |   return executor_work_guard<Executor>(ex);
      |          ^
<source>:10:21: note: in instantiation of function template specialization 'boost::asio::make_work_guard<boost::asio::strand<boost::asio::any_io_executor>>' requested here
   10 |     auto wg = asio::make_work_guard(strand);
      |                     ^
In file included from <source>:1:
In file included from /opt/compiler-explorer/libs/boost_1_83_0/boost/asio.hpp:188:
/opt/compiler-explorer/libs/boost_1_83_0/boost/asio/strand.hpp:260:15: error: no member named 'on_work_finished' in 'boost::asio::any_io_executor'
  260 |     executor_.on_work_finished();
      |     ~~~~~~~~~ ^
/opt/compiler-explorer/libs/boost_1_83_0/boost/asio/executor_work_guard.hpp:124:17: note: in instantiation of member function 'boost::asio::strand<boost::asio::any_io_executor>::on_work_finished' requested here
  124 |       executor_.on_work_finished();
      |                 ^
<source>:10:15: note: in instantiation of member function 'boost::asio::executor_work_guard<boost::asio::strand<boost::asio::any_io_executor>>::~executor_work_guard' requested here
   10 |     auto wg = asio::make_work_guard(strand);
      |               ^
2 errors generated.
ASM generation compiler returned: 1
In file included from <source>:1:
In file included from /opt/compiler-explorer/libs/boost_1_83_0/boost/asio.hpp:188:
/opt/compiler-explorer/libs/boost_1_83_0/boost/asio/strand.hpp:251:15: error: no member named 'on_work_started' in 'boost::asio::any_io_executor'
  251 |     executor_.on_work_started();
      |     ~~~~~~~~~ ^
/opt/compiler-explorer/libs/boost_1_83_0/boost/asio/executor_work_guard.hpp:101:15: note: in instantiation of member function 'boost::asio::strand<boost::asio::any_io_executor>::on_work_started' requested here
  101 |     executor_.on_work_started();
      |               ^
/opt/compiler-explorer/libs/boost_1_83_0/boost/asio/executor_work_guard.hpp:260:10: note: in instantiation of member function 'boost::asio::executor_work_guard<boost::asio::strand<boost::asio::any_io_executor>>::executor_work_guard' requested here
  260 |   return executor_work_guard<Executor>(ex);
      |          ^
<source>:10:21: note: in instantiation of function template specialization 'boost::asio::make_work_guard<boost::asio::strand<boost::asio::any_io_executor>>' requested here
   10 |     auto wg = asio::make_work_guard(strand);
      |                     ^
In file included from <source>:1:
In file included from /opt/compiler-explorer/libs/boost_1_83_0/boost/asio.hpp:188:
/opt/compiler-explorer/libs/boost_1_83_0/boost/asio/strand.hpp:260:15: error: no member named 'on_work_finished' in 'boost::asio::any_io_executor'
  260 |     executor_.on_work_finished();
      |     ~~~~~~~~~ ^
/opt/compiler-explorer/libs/boost_1_83_0/boost/asio/executor_work_guard.hpp:124:17: note: in instantiation of member function 'boost::asio::strand<boost::asio::any_io_executor>::on_work_finished' requested here
  124 |       executor_.on_work_finished();
      |                 ^
<source>:10:15: note: in instantiation of member function 'boost::asio::executor_work_guard<boost::asio::strand<boost::asio::any_io_executor>>::~executor_work_guard' requested here
   10 |     auto wg = asio::make_work_guard(strand);
      |               ^
2 errors generated.
Execution build compiler returned: 1