GorNishanov updated this revision to Diff 140903.
GorNishanov added a comment.
incorporated review feedback
https://reviews.llvm.org/D45121
Files:
include/experimental/coroutine
test/std/experimental/language.support/support.coroutines/coroutine.handle/coroutine.handle.noop/noop_coroutine.pass.cpp
Index: test/std/experimental/language.support/support.coroutines/coroutine.handle/coroutine.handle.noop/noop_coroutine.pass.cpp
===================================================================
--- /dev/null
+++ test/std/experimental/language.support/support.coroutines/coroutine.handle/coroutine.handle.noop/noop_coroutine.pass.cpp
@@ -0,0 +1,64 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11
+// XFAIL: clang-5, clang-6
+// <experimental/coroutine>
+// struct noop_coroutine_promise;
+// using noop_coroutine_handle = coroutine_handle<noop_coroutine_promise>;
+// noop_coroutine_handle noop_coroutine() noexcept;
+
+#include <experimental/coroutine>
+#include <type_traits>
+#include <cassert>
+
+namespace coro = std::experimental;
+
+static_assert(std::is_same<coro::coroutine_handle<coro::noop_coroutine_promise>, coro::noop_coroutine_handle>::value, "");
+static_assert(std::is_same<decltype(coro::noop_coroutine()), coro::noop_coroutine_handle>::value, "");
+
+// template <> struct coroutine_handle<noop_coroutine_promise> : coroutine_handle<>
+// {
+// // 18.11.2.7 noop observers
+// constexpr explicit operator bool() const noexcept;
+// constexpr bool done() const noexcept;
+
+// // 18.11.2.8 noop resumption
+// constexpr void operator()() const noexcept;
+// constexpr void resume() const noexcept;
+// constexpr void destroy() const noexcept;
+
+// // 18.11.2.9 noop promise access
+// noop_coroutine_promise& promise() const noexcept;
+
+// // 18.11.2.10 noop address
+// constexpr void* address() const noexcept;
+
+int main()
+{
+ auto h = coro::noop_coroutine();
+ coro::coroutine_handle<> base = h;
+
+ assert(h);
+ assert(base);
+
+ assert(!h.done());
+ assert(!base.done());
+
+ h.resume();
+ h.destroy();
+ h();
+
+ h.promise();
+ assert(h.address() == base.address());
+ assert(h.address() != nullptr);
+ assert(coro::coroutine_handle<>::from_address(h.address()) == base);
+}
+
Index: include/experimental/coroutine
===================================================================
--- include/experimental/coroutine
+++ include/experimental/coroutine
@@ -259,6 +259,45 @@
}
};
+#if __has_builtin(__builtin_coro_noop)
+struct noop_coroutine_promise {};
+
+template <>
+class _LIBCPP_TEMPLATE_VIS coroutine_handle<noop_coroutine_promise>
+ : public coroutine_handle<> {
+ using _Base = coroutine_handle<>;
+ using _Promise = noop_coroutine_promise;
+public:
+
+ _LIBCPP_INLINE_VISIBILITY
+ _Promise& promise() const {
+ return *reinterpret_cast<_Promise*>(
+ __builtin_coro_promise(this->__handle_, __alignof(_Promise), false));
+ }
+
+ constexpr explicit operator bool() const noexcept { return true; }
+ constexpr bool done() const noexcept { return false; }
+
+ constexpr void operator()() const noexcept {}
+ constexpr void resume() const noexcept {}
+ constexpr void destroy() const noexcept {}
+
+private:
+ friend coroutine_handle<noop_coroutine_promise> noop_coroutine() _NOEXCEPT;
+
+ coroutine_handle() {
+ this->__handle_ = __builtin_coro_noop();
+ }
+};
+
+using noop_coroutine_handle = coroutine_handle<noop_coroutine_promise>;
+
+inline _LIBCPP_INLINE_VISIBILITY
+noop_coroutine_handle noop_coroutine() _NOEXCEPT {
+ return {};
+}
+#endif // __has_builtin(__builtin_coro_noop)
+
struct _LIBCPP_TYPE_VIS suspend_never {
_LIBCPP_ALWAYS_INLINE
bool await_ready() const _NOEXCEPT { return true; }
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits