diff --git a/include/asio/awaitable.hpp b/include/asio/awaitable.hpp index b0b5b6a0e4..11b153bfca 100644 --- a/include/asio/awaitable.hpp +++ b/include/asio/awaitable.hpp @@ -47,11 +47,20 @@ template class awaitable_frame; } // namespace detail +#if !defined(ASIO_AWAITABLE_FWD_DECL) +#define ASIO_AWAITABLE_FWD_DECL + +// Forward declaration with defaulted arguments. +template +class awaitable; + +#endif // !defined(ASIO_AWAITABLE_FWD_DECL) + /// The return type of a coroutine or asynchronous operation. /** * @sa @ref overview_cpp20_coroutines "C++20 coroutines support" */ -template +template class ASIO_NODISCARD awaitable { public: diff --git a/include/asio/fwd.hpp b/include/asio/fwd.hpp index 2650831888..82c7560a21 100644 --- a/include/asio/fwd.hpp +++ b/include/asio/fwd.hpp @@ -82,6 +82,19 @@ class any_completion_executor; #endif // defined(ASIO_USE_TS_EXECUTOR_AS_DEFAULT) +#if defined(ASIO_HAS_CO_AWAIT) + +#if !defined(ASIO_AWAITABLE_FWD_DECL) +#define ASIO_AWAITABLE_FWD_DECL + +// Forward declaration with defaulted arguments. +template +class awaitable; + +#endif // !defined(ASIO_AWAITABLE_FWD_DECL) + +#endif // defined(ASIO_HAS_CO_AWAIT) + template class any_completion_handler; diff --git a/src/tests/unit/fwd_first.cpp b/src/tests/unit/fwd_first.cpp index 6a5947f1bd..48781edac9 100644 --- a/src/tests/unit/fwd_first.cpp +++ b/src/tests/unit/fwd_first.cpp @@ -16,6 +16,10 @@ // Test that header file is self-contained. #include "asio/fwd.hpp" +#if defined(ASIO_HAS_CO_AWAIT) +asio::awaitable fwd_awaitable(); +#endif // defined(ASIO_HAS_CO_AWAIT) + // Test that forward declarations don't conflict with full declarations. #include "asio.hpp"