Skip to content

Conversation

@RobertLeahy
Copy link
Contributor

@RobertLeahy RobertLeahy commented Nov 27, 2025

Previously async_result<asioexec::completion_token, ...>:: and async_result<asioexec::use_sender, ...>::initiate:

  • Used automatic return type deduction, and
  • Were not constrained on any properties of the arguments thereto

This meant that initiating functions of the form were problematic:

  template <typename AsyncReadStream, typename Allocator,
      BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
        std::size_t)) ReadToken = default_completion_token_t<
          typename AsyncReadStream::executor_type>>
  inline auto async_read(AsyncReadStream& s, basic_streambuf<Allocator>& b,
      ReadToken&& token = default_completion_token_t<
        typename AsyncReadStream::executor_type>(),
      constraint_t<
        !is_completion_condition<ReadToken>::value
      > = 0)
    -> decltype(
      async_initiate<ReadToken,
        void (boost::system::error_code, std::size_t)>(
          declval<detail::initiate_async_read_dynbuf_v1<AsyncReadStream>>(),
          token, basic_streambuf_ref<Allocator>(b), transfer_all()));

Note that:

  • The above is an actual initiating function from Asio, and
  • The return type is defined in terms of the type returned by async_initiate

The latter of the two points above means that the compiler must determine the type of an expression involving async_initiate. Since that expression transitively defers to async_result<...>::initiate this meant that the compiler had to determine the return type thereof. Since (as mentioned above) that function uses automatic return type deduction that meant the compiler had to substitute into the body thereof. Since errors in such a context are not SFINAE-friendly this meant that if the variadic pack of arguments thereto did not consist only of decay- copyable types there would be a hard compilation error (rather than the overload simply being removed from the candidate set).

Both newly-added unit tests failed to compile before this change due to the above.

Added a constraint to both previously-mentioned initiate functions to address the above.

Previously async_result<asioexec::completion_token, ...>:: and
async_result<asioexec::use_sender, ...>::initiate:

- Used automatic return type deduction, and
- Were not constrained on any properties of the arguments thereto

This meant that initiating functions of the form were problematic:

  template <typename AsyncReadStream, typename Allocator,
      BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
        std::size_t)) ReadToken = default_completion_token_t<
          typename AsyncReadStream::executor_type>>
  inline auto async_read(AsyncReadStream& s, basic_streambuf<Allocator>& b,
      ReadToken&& token = default_completion_token_t<
        typename AsyncReadStream::executor_type>(),
      constraint_t<
        !is_completion_condition<ReadToken>::value
      > = 0)
    -> decltype(
      async_initiate<ReadToken,
        void (boost::system::error_code, std::size_t)>(
          declval<detail::initiate_async_read_dynbuf_v1<AsyncReadStream>>(),
          token, basic_streambuf_ref<Allocator>(b), transfer_all()));

Note that:

- The above is an actual initiating function from Asio, and
- The return type is defined in terms of the type returned by
  async_initiate

The latter of the two points above means that the compiler must
determine the type of an expression involving async_initiate. Since that
expression transitively defers to async_result<...>::initiate this meant
that the compiler had to determine the return type thereof. Since (as
mentioned above) that function uses automatic return type deduction that
meant the compiler had to substitute into the body thereof. Since errors
in such a context are not SFINAE-friendly this meant that if the
variadic pack of arguments thereto did not consist only of decay-
copyable types there would be a hard compilation error (rather than the
overload simply being removed from the candidate set).

Both newly-added unit tests failed to compile before this change due to
the above.

Added a constraint to both previously-mentioned initiate functions to
address the above.
@copy-pr-bot
Copy link

copy-pr-bot bot commented Nov 27, 2025

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@RobertLeahy
Copy link
Contributor Author

Addresses #1684.

@ericniebler ericniebler linked an issue Nov 27, 2025 that may be closed by this pull request
@ericniebler
Copy link
Collaborator

/ok to test 5953eb3

@ericniebler ericniebler merged commit b273eee into NVIDIA:main Nov 27, 2025
18 checks passed
@ericniebler
Copy link
Collaborator

thanks, robert!

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

Successfully merging this pull request may close these issues.

asio completion_token error with async_read and streambuf

2 participants