Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spawn() doesn't support move-only return values after boost 1.80.0 #1543

Open
cbodley opened this issue Oct 9, 2024 · 0 comments
Open

spawn() doesn't support move-only return values after boost 1.80.0 #1543

cbodley opened this issue Oct 9, 2024 · 0 comments

Comments

@cbodley
Copy link
Contributor

cbodley commented Oct 9, 2024

minimal reproducer fails to compile against the boost-1.86.0 tag with both gcc (GCC) 14.2.1 and clang version 18.1.8 (both logs in https://gist.github.com/cbodley/1b3a85b6281133fc8ea96dfc1b9c2f5b)

#include <exception>
#include <iostream>
#include <memory>
#include <boost/asio.hpp>
#include <boost/asio/spawn.hpp>

int main()
{
  boost::asio::io_context ctx;
  boost::asio::spawn(ctx, [] (boost::asio::yield_context yield) {
        return std::make_unique<int>(42);
      }, [] (std::exception_ptr eptr, std::unique_ptr<int> result) {
        if (eptr) {
          std::rethrow_exception(eptr);
        } else {
          std::cout << *result << '\n';
        }
      });
  ctx.run();
  return 0;
}

see godbolt example in https://godbolt.org/z/bMjj11h7o

interestingly, this example does compile successfully against boost-1.80.0 where the feature was introduced:

Changed spawn() to be a completion token-based asynchronous operation. This introduces new spawn() overloads that conform to the requirements for asynchronous operations.

but fails with any boost version after 1.80.0

the equivalent example with co_spawn() compiles and runs successfully:

#include <exception>
#include <iostream>
#include <memory>
#include <boost/asio.hpp>
#include <boost/asio/co_spawn.hpp>

int main()
{
  boost::asio::io_context ctx;
  boost::asio::co_spawn(ctx, [] () -> boost::asio::awaitable<std::unique_ptr<int>> {
        co_return std::make_unique<int>(42);                     
      }, [] (std::exception_ptr eptr, std::unique_ptr<int> result) {
        if (eptr) {
          std::rethrow_exception(eptr);
        } else {
          std::cout << *result << '\n';
        }
      });
  ctx.run();
  return 0;
}
cbodley added a commit to cbodley/asio that referenced this issue Oct 18, 2024
add a test case to reproduce chriskohlhoff#1543

Signed-off-by: Casey Bodley <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant