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

LWG-3460 Unimplementable noop_coroutine_handle guarantees #1452

Merged
merged 8 commits into from
Dec 2, 2020
26 changes: 20 additions & 6 deletions stl/inc/coroutine
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected:
};

template <class _Promise>
struct coroutine_handle : coroutine_handle<> {
struct coroutine_handle : private coroutine_handle<> {
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
using coroutine_handle<>::coroutine_handle;

_NODISCARD static coroutine_handle from_promise(_Promise& _Prom) noexcept { // strengthened
Expand All @@ -109,12 +109,24 @@ struct coroutine_handle : coroutine_handle<> {
return *this;
}

using coroutine_handle<>::address;
_NODISCARD static constexpr coroutine_handle from_address(void* const _Addr) noexcept { // strengthened
coroutine_handle _Result;
_Result._Ptr = _Addr;
return _Result;
}

constexpr operator coroutine_handle<>() const noexcept {
return static_cast<const coroutine_handle<>&>(*this);
}

using coroutine_handle<>::operator bool;
using coroutine_handle<>::done;

using coroutine_handle<>::operator();
using coroutine_handle<>::resume;
using coroutine_handle<>::destroy;

_NODISCARD _Promise& promise() const noexcept { // strengthened
return *reinterpret_cast<_Promise*>(__builtin_coro_promise(_Ptr, 0, false));
}
Expand Down Expand Up @@ -145,9 +157,13 @@ struct noop_coroutine_promise {};

// STRUCT coroutine_handle<noop_coroutine_promise>
template <>
struct coroutine_handle<noop_coroutine_promise> : coroutine_handle<> {
struct coroutine_handle<noop_coroutine_promise> : private coroutine_handle<> {
friend coroutine_handle noop_coroutine() noexcept;

constexpr operator coroutine_handle<>() const noexcept {
return static_cast<const coroutine_handle<>&>(*this);
}

constexpr explicit operator bool() const noexcept {
return true;
}
Expand All @@ -159,11 +175,9 @@ struct coroutine_handle<noop_coroutine_promise> : coroutine_handle<> {
constexpr void resume() const noexcept {}
constexpr void destroy() const noexcept {}

using _Promise = noop_coroutine_promise;

_NODISCARD _Promise& promise() const noexcept {
_NODISCARD noop_coroutine_promise& promise() const noexcept {
// Returns a reference to the associated promise
return *reinterpret_cast<_Promise*>(__builtin_coro_promise(_Ptr, 0, false));
return *reinterpret_cast<noop_coroutine_promise*>(__builtin_coro_promise(_Ptr, 0, false));
}

private:
Expand Down