aboutsummaryrefslogtreecommitdiffstats
path: root/test/std/experimental/language.support/support.coroutines/end.to.end/bool_await_suspend.pass.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-06-01 20:59:10 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-06-01 20:59:10 +0000
commitedb11085302f80f38c9d976f003aa1c9002c7abb (patch)
treeedfe9dcac670e9f47ee7fdee893130fcf86ba196 /test/std/experimental/language.support/support.coroutines/end.to.end/bool_await_suspend.pass.cpp
parent10a0bef720b6882fce588a10b07b0584d62eac76 (diff)
downloadsrc-edb11085302f80f38c9d976f003aa1c9002c7abb.tar.gz
src-edb11085302f80f38c9d976f003aa1c9002c7abb.zip
Vendor import of libc++ trunk r304460:vendor/libc++/libc++-trunk-r304460
Notes
Notes: svn path=/vendor/libc++/dist/; revision=319467 svn path=/vendor/libc++/libc++-trunk-r304460/; revision=319468; tag=vendor/libc++/libc++-trunk-r304460
Diffstat (limited to 'test/std/experimental/language.support/support.coroutines/end.to.end/bool_await_suspend.pass.cpp')
-rw-r--r--test/std/experimental/language.support/support.coroutines/end.to.end/bool_await_suspend.pass.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/test/std/experimental/language.support/support.coroutines/end.to.end/bool_await_suspend.pass.cpp b/test/std/experimental/language.support/support.coroutines/end.to.end/bool_await_suspend.pass.cpp
new file mode 100644
index 000000000000..9c3becffc0ac
--- /dev/null
+++ b/test/std/experimental/language.support/support.coroutines/end.to.end/bool_await_suspend.pass.cpp
@@ -0,0 +1,66 @@
+// -*- 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
+
+#include <experimental/coroutine>
+#include <cassert>
+
+using namespace std::experimental;
+
+struct coro_t {
+ struct promise_type {
+ coro_t get_return_object() {
+ return coroutine_handle<promise_type>::from_promise(*this);
+ }
+ suspend_never initial_suspend() { return {}; }
+ suspend_never final_suspend() { return {}; }
+ void return_void(){}
+ void unhandled_exception() {}
+ };
+ coro_t(coroutine_handle<promise_type> hh) : h(hh) {}
+ coroutine_handle<promise_type> h;
+};
+
+struct NoSuspend {
+ bool await_ready() { return false; }
+ void await_resume() {}
+ template <typename F> bool await_suspend(F) { return false; }
+};
+
+struct DoSuspend {
+ bool await_ready() { return false; }
+ void await_resume() {}
+ template <typename F> bool await_suspend(F) { return true; }
+};
+
+bool f_started, f_resumed = false;
+coro_t f() {
+ f_started = true;
+ co_await DoSuspend{};
+ f_resumed = true;
+}
+
+bool g_started, g_resumed = false;
+coro_t g() {
+ g_started = true;
+ co_await NoSuspend{};
+ g_resumed = true;
+}
+
+int main() {
+ assert(!f_started && !f_resumed && !g_started && !g_resumed);
+ auto fret = f();
+ assert(f_started && !f_resumed);
+ fret.h.destroy();
+ assert(f_started && !f_resumed);
+ g();
+ assert(g_started && g_resumed);
+}