aboutsummaryrefslogtreecommitdiffstats
path: root/test/std/experimental/language.support/support.coroutines/end.to.end/await_result.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/await_result.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/await_result.pass.cpp')
-rw-r--r--test/std/experimental/language.support/support.coroutines/end.to.end/await_result.pass.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/test/std/experimental/language.support/support.coroutines/end.to.end/await_result.pass.cpp b/test/std/experimental/language.support/support.coroutines/end.to.end/await_result.pass.cpp
new file mode 100644
index 000000000000..769a825df001
--- /dev/null
+++ b/test/std/experimental/language.support/support.coroutines/end.to.end/await_result.pass.cpp
@@ -0,0 +1,69 @@
+// -*- 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() {
+ coroutine_handle<promise_type>{};
+ return {};
+ }
+ suspend_never initial_suspend() { return {}; }
+ suspend_never final_suspend() { return {}; }
+ void return_void(){}
+ static void unhandled_exception() {}
+ };
+};
+
+struct B {
+ ~B() {}
+ bool await_ready() { return true; }
+ B await_resume() { return {}; }
+ template <typename F> void await_suspend(F) {}
+};
+
+
+struct A {
+ ~A(){}
+ bool await_ready() { return true; }
+ int await_resume() { return 42; }
+ template <typename F> void await_suspend(F) {}
+};
+
+int last_value = -1;
+void set_value(int x) {
+ last_value = x;
+}
+
+coro_t f(int n) {
+ if (n == 0) {
+ set_value(0);
+ co_return;
+ }
+ int val = co_await A{};
+ ((void)val);
+ set_value(42);
+}
+
+coro_t g() { B val = co_await B{}; }
+
+int main() {
+ last_value = -1;
+ f(0);
+ assert(last_value == 0);
+ f(1);
+ assert(last_value == 42);
+}