Get <experimental/coroutine> working in C++03.

Clang supports coroutines in all dialects; Therefore libc++ should too,
otherwise the Clang extension is unusable.

I'm not convinced extending support to C++03 is a feasible long term
plan, since as the library grows to offer things like generators it
will be come increasingly difficult to limit the implementation to C++03.

However for the time being supporting C++03 isn't a big deal.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@303963 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Fiselier
2017-05-26 03:02:54 +00:00
parent c80ef6ed28
commit 4aec787d15
2 changed files with 94 additions and 33 deletions

View File

@@ -0,0 +1,57 @@
// -*- 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.
//
//===----------------------------------------------------------------------===//
// REQUIRES: fcoroutines-ts
// RUN: %build -fcoroutines-ts
// RUN: %run
// A simple "breathing" test that checks that <experimental/coroutine>
// can be parsed and used in all dialects, including C++03 in order to match
// Clang's behavior.
#include <experimental/coroutine>
namespace coro = std::experimental::coroutines_v1;
coro::suspend_always sa;
coro::suspend_never sn;
struct MyFuture {
struct promise_type {
typedef coro::coroutine_handle<promise_type> HandleT;
coro::suspend_always initial_suspend() { return sa; }
coro::suspend_never final_suspend() { return sn; }
coro::suspend_never yield_value(int) { return sn; }
MyFuture get_return_object() {
MyFuture f(HandleT::from_address(this));
return f;
}
void return_void() {}
void unhandled_exception() {}
};
typedef promise_type::HandleT HandleT;
MyFuture() : p() {}
MyFuture(HandleT h) : p(h) {}
private:
coro::coroutine_handle<promise_type> p;
};
MyFuture test_coro() {
co_await sn;
co_yield 42;
co_return;
}
int main()
{
MyFuture f = test_coro();
}