Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++14 -fcoroutines-ts \
// RUN: -fsyntax-only -Wignored-qualifiers -Wno-error=return-type -verify \
// RUN: -fblocks -Wno-unreachable-code -Wno-unused-value

// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++14 -fcoroutines-ts \
// RUN: -fsyntax-only -Wignored-qualifiers -Wno-error=return-type -verify \
// RUN: -fblocks -Wno-unreachable-code -Wno-unused-value \
// RUN: -DDISABLE_WARNING -Wno-deprecated-experimental-coroutine -Wno-coroutine-missing-unhandled-exception

#if __has_feature(cxx_exceptions)
#error This test requires exceptions be disabled
#endif

#include "Inputs/std-coroutine-exp-namespace.h"

using std::experimental::suspend_always;
using std::experimental::suspend_never;

#ifndef DISABLE_WARNING
struct promise_void { // expected-note {{defined here}}
#else
struct promise_void {
#endif
void get_return_object();
suspend_always initial_suspend();
suspend_always final_suspend() noexcept;
void return_void();
};

template <typename... T>
struct std::experimental::coroutine_traits<void, T...> { using promise_type = promise_void; };

#ifndef DISABLE_WARNING
void test0() { // expected-warning {{'promise_void' is required to declare the member 'unhandled_exception()' when exceptions are enabled}}
co_return; // expected-warning {{support for 'std::experimental::coroutine_traits' will be removed}}
// expected-note@Inputs/std-coroutine-exp-namespace.h:8 {{'coroutine_traits' declared here}}
}
#else
void test0() { // expected-no-diagnostics
co_return;
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++14 -fcoroutines-ts -fsyntax-only -Wall -Wextra -Wuninitialized -fblocks
#include "Inputs/std-coroutine-exp-namespace.h"

using namespace std::experimental;

struct A {
bool await_ready() { return true; }
int await_resume() { return 42; }
template <typename F>
void await_suspend(F) {}
};

struct coro_t {
struct promise_type {
coro_t get_return_object() { return {}; }
suspend_never initial_suspend() { return {}; }
suspend_never final_suspend() noexcept { return {}; }
A yield_value(int) { return {}; }
void return_void() {}
static void unhandled_exception() {}
};
};

coro_t f(int n) {
if (n == 0)
co_return;
co_yield 42;
int x = co_await A{};
}

template <class Await>
coro_t g(int n) {
if (n == 0)
co_return;
co_yield 42;
int x = co_await Await{};
}

int main() {
f(0);
g<A>(0);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// RUN: %clang_cc1 -verify %s -stdlib=libc++ -std=c++1z -fcoroutines-ts -fsyntax-only

namespace std::experimental {
template <class Promise = void>
struct coroutine_handle;

template <>
struct coroutine_handle<void> {
coroutine_handle() = default;
static coroutine_handle from_address(void *) noexcept;
void *address() const;
};

template <class Promise>
struct coroutine_handle : public coroutine_handle<> {
};

template <class... Args>
struct void_t_imp {
using type = void;
};
template <class... Args>
using void_t = typename void_t_imp<Args...>::type;

template <class T, class = void>
struct traits_sfinae_base {};

template <class T>
struct traits_sfinae_base<T, void_t<typename T::promise_type>> {
using promise_type = typename T::promise_type;
};

template <class Ret, class... Args>
struct coroutine_traits : public traits_sfinae_base<Ret> {};
// expected-note@-1{{declared here}}
} // namespace std::experimental

struct suspend_never {
bool await_ready() noexcept;
void await_suspend(std::experimental::coroutine_handle<>) noexcept;
void await_resume() noexcept;
};

struct task {
struct promise_type {
auto initial_suspend() { return suspend_never{}; }
auto final_suspend() noexcept { return suspend_never{}; }
auto get_return_object() { return task{}; }
static void unhandled_exception() {}
void return_void() {}
};
};

namespace std::experimental {
template <>
struct coroutine_handle<task::promise_type> : public coroutine_handle<> {
coroutine_handle<task::promise_type> *address() const; // expected-warning {{return type of 'coroutine_handle<>::address should be 'void*'}}
};
} // namespace std::experimental

struct awaitable {
bool await_ready();

std::experimental::coroutine_handle<task::promise_type>
await_suspend(std::experimental::coroutine_handle<> handle);
void await_resume();
} a;

task f() {
co_await a; // expected-warning {{support for 'std::experimental::coroutine_traits' will be removed}}
}

int main() {
f();
return 0;
}
1,443 changes: 1,443 additions & 0 deletions clang/test/SemaCXX/coroutines-exp-namespace.cpp

Large diffs are not rendered by default.