Work around clang coroutine allocation elision bug.

Declare variadic when_all_ready() as forced-inline to
avoid it returning a reference to a when_all_read_task
object allocated in the stack-frame of when_all_ready().
This commit is contained in:
Lewis Baker 2017-10-17 22:13:10 +10:30
parent a3bca2c066
commit 18d2b4d5aa
2 changed files with 11 additions and 1 deletions

View File

@ -36,6 +36,14 @@
# define CPPCORO_ASSUME(X)
#endif
#if CPPCORO_COMPILER_MSVC
# define CPPCORO_FORCE_INLINE __declspec(force_inline)
#elif CPPCORO_COMPILER_CLANG
# define CPPCORO_FORCE_INLINE __attribute__((always_inline))
#else
# define CPPCORO_FORCE_INLINE inline
#endif
/////////////////////////////////////////////////////////////////////////////
// OS Detection

View File

@ -5,6 +5,7 @@
#ifndef CPPCORO_WHEN_ALL_READY_HPP_INCLUDED
#define CPPCORO_WHEN_ALL_READY_HPP_INCLUDED
#include <cppcoro/config.hpp>
#include <cppcoro/awaitable_traits.hpp>
#include <cppcoro/is_awaitable.hpp>
@ -23,7 +24,8 @@ namespace cppcoro
typename... AWAITABLES,
std::enable_if_t<std::conjunction_v<
is_awaitable<detail::unwrap_reference_t<std::remove_reference_t<AWAITABLES>>>...>, int> = 0>
[[nodiscard]] auto when_all_ready(AWAITABLES&&... awaitables)
[[nodiscard]]
CPPCORO_FORCE_INLINE auto when_all_ready(AWAITABLES&&... awaitables)
{
return detail::when_all_ready_awaitable<std::tuple<detail::when_all_task<
typename awaitable_traits<detail::unwrap_reference_t<std::remove_reference_t<AWAITABLES>>>::await_result_t>...>>(