Index: libcxx/CMakeLists.txt =================================================================== --- libcxx/CMakeLists.txt +++ libcxx/CMakeLists.txt @@ -563,7 +563,7 @@ endif() if (LIBCXX_CONFIGURE_IDE) - # This simply allows IDE to process + # This simply allows IDE to process target_add_compile_flags_if_supported(${target} PRIVATE -fcoroutines-ts) endif() Index: libcxx/include/CMakeLists.txt =================================================================== --- libcxx/include/CMakeLists.txt +++ libcxx/include/CMakeLists.txt @@ -305,6 +305,7 @@ complex.h concepts condition_variable + coroutine csetjmp csignal cstdarg Index: libcxx/include/coroutine =================================================================== --- /dev/null +++ libcxx/include/coroutine @@ -0,0 +1,296 @@ +// -*- C++ -*- +//===----------------------------- coroutine -----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_COROUTINE +#define _LIBCPP_COROUTINE + +/** + coroutine synopsis + +// C++next + +namespace std { + + // 18.11.1 coroutine traits +template +class coroutine_traits; +// 18.11.2 coroutine handle +template +class coroutine_handle; +// 18.11.2.7 comparison operators: +bool operator==(coroutine_handle<> x, coroutine_handle<> y) _NOEXCEPT; +bool operator!=(coroutine_handle<> x, coroutine_handle<> y) _NOEXCEPT; +bool operator<(coroutine_handle<> x, coroutine_handle<> y) _NOEXCEPT; +bool operator<=(coroutine_handle<> x, coroutine_handle<> y) _NOEXCEPT; +bool operator>=(coroutine_handle<> x, coroutine_handle<> y) _NOEXCEPT; +bool operator>(coroutine_handle<> x, coroutine_handle<> y) _NOEXCEPT; +// 18.11.3 trivial awaitables +struct suspend_never; +struct suspend_always; +// 18.11.2.8 hash support: +template struct hash; +template struct hash>; + +} // namespace std + + */ + +#include <__config> +#include +#include +#include +#include // for hash +#include +#include <__debug> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#ifdef _LIBCPP_HAS_NO_COROUTINES +#if defined(_LIBCPP_WARNING) +_LIBCPP_WARNING(" cannot be used with this compiler") +#else +#warning cannot be used with this compiler +#endif +#endif + +#ifndef _LIBCPP_HAS_NO_COROUTINES + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +struct __coroutine_traits_sfinae {}; + +template +struct __coroutine_traits_sfinae<_Tp, typename __void_t::type> { + using promise_type = typename _Tp::promise_type; +}; + +template +struct coroutine_traits : public __coroutine_traits_sfinae<_Ret> {}; + +template +class _LIBCPP_TEMPLATE_VIS coroutine_handle; + +template <> +class _LIBCPP_TEMPLATE_VIS coroutine_handle { +public: + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR coroutine_handle() _NOEXCEPT : __handle_(nullptr) {} + + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR coroutine_handle(nullptr_t) _NOEXCEPT : __handle_(nullptr) {} + + _LIBCPP_INLINE_VISIBILITY + coroutine_handle& operator=(nullptr_t) _NOEXCEPT { + __handle_ = nullptr; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR void* address() const _NOEXCEPT { return __handle_; } + + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR explicit operator bool() const _NOEXCEPT { return __handle_; } + + _LIBCPP_INLINE_VISIBILITY + void operator()() { resume(); } + + _LIBCPP_INLINE_VISIBILITY + void resume() { + _LIBCPP_ASSERT(__is_suspended(), "resume() can only be called on suspended coroutines"); + _LIBCPP_ASSERT(!done(), "resume() has undefined behavior when the coroutine is done"); + __builtin_coro_resume(__handle_); + } + + _LIBCPP_INLINE_VISIBILITY + void destroy() { + _LIBCPP_ASSERT(__is_suspended(), "destroy() can only be called on suspended coroutines"); + __builtin_coro_destroy(__handle_); + } + + _LIBCPP_INLINE_VISIBILITY + bool done() const { + _LIBCPP_ASSERT(__is_suspended(), "done() can only be called on suspended coroutines"); + return __builtin_coro_done(__handle_); + } + +public: + _LIBCPP_INLINE_VISIBILITY + static coroutine_handle from_address(void* __addr) _NOEXCEPT { + coroutine_handle __tmp; + __tmp.__handle_ = __addr; + return __tmp; + } + + // FIXME: Should from_address(nullptr) be allowed? + _LIBCPP_INLINE_VISIBILITY + static coroutine_handle from_address(nullptr_t) _NOEXCEPT { return coroutine_handle(nullptr); } + + template + static coroutine_handle from_address(_Tp*) { + static_assert(_CallIsValid, "coroutine_handle::from_address cannot be called with " + "non-void pointers"); + } + +private: + bool __is_suspended() const _NOEXCEPT { + // FIXME actually implement a check for if the coro is suspended. + return __handle_; + } + + template + friend class coroutine_handle; + void* __handle_; +}; + +// 18.11.2.7 comparison operators: +inline _LIBCPP_INLINE_VISIBILITY bool operator==(coroutine_handle<> __x, coroutine_handle<> __y) _NOEXCEPT { + return __x.address() == __y.address(); +} +inline _LIBCPP_INLINE_VISIBILITY bool operator!=(coroutine_handle<> __x, coroutine_handle<> __y) _NOEXCEPT { + return !(__x == __y); +} +inline _LIBCPP_INLINE_VISIBILITY bool operator<(coroutine_handle<> __x, coroutine_handle<> __y) _NOEXCEPT { + return less()(__x.address(), __y.address()); +} +inline _LIBCPP_INLINE_VISIBILITY bool operator>(coroutine_handle<> __x, coroutine_handle<> __y) _NOEXCEPT { + return __y < __x; +} +inline _LIBCPP_INLINE_VISIBILITY bool operator<=(coroutine_handle<> __x, coroutine_handle<> __y) _NOEXCEPT { + return !(__x > __y); +} +inline _LIBCPP_INLINE_VISIBILITY bool operator>=(coroutine_handle<> __x, coroutine_handle<> __y) _NOEXCEPT { + return !(__x < __y); +} + +template +class _LIBCPP_TEMPLATE_VIS coroutine_handle : public coroutine_handle<> { + using _Base = coroutine_handle<>; + +public: +#ifndef _LIBCPP_CXX03_LANG + // 18.11.2.1 construct/reset + using coroutine_handle<>::coroutine_handle; +#else + _LIBCPP_INLINE_VISIBILITY coroutine_handle() _NOEXCEPT : _Base() {} + _LIBCPP_INLINE_VISIBILITY coroutine_handle(nullptr_t) _NOEXCEPT : _Base(nullptr) {} +#endif + _LIBCPP_INLINE_VISIBILITY + coroutine_handle& operator=(nullptr_t) _NOEXCEPT { + _Base::operator=(nullptr); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + _Promise& promise() const { + return *static_cast<_Promise*>(__builtin_coro_promise(this->__handle_, _LIBCPP_ALIGNOF(_Promise), false)); + } + +public: + _LIBCPP_INLINE_VISIBILITY + static coroutine_handle from_address(void* __addr) _NOEXCEPT { + coroutine_handle __tmp; + __tmp.__handle_ = __addr; + return __tmp; + } + + // NOTE: this overload isn't required by the standard but is needed so + // the deleted _Promise* overload doesn't make from_address(nullptr) + // ambiguous. + // FIXME: should from_address work with nullptr? + _LIBCPP_INLINE_VISIBILITY + static coroutine_handle from_address(nullptr_t) _NOEXCEPT { return coroutine_handle(nullptr); } + + template + static coroutine_handle from_address(_Tp*) { + static_assert(_CallIsValid, "coroutine_handle::from_address cannot be called with " + "non-void pointers"); + } + + template + static coroutine_handle from_address(_Promise*) { + static_assert(_CallIsValid, "coroutine_handle::from_address cannot be used with " + "pointers to the coroutine's promise type; use 'from_promise' instead"); + } + + _LIBCPP_INLINE_VISIBILITY + static coroutine_handle from_promise(_Promise& __promise) _NOEXCEPT { + typedef typename remove_cv<_Promise>::type _RawPromise; + coroutine_handle __tmp; + __tmp.__handle_ = + __builtin_coro_promise(_VSTD::addressof(const_cast<_RawPromise&>(__promise)), _LIBCPP_ALIGNOF(_Promise), true); + return __tmp; + } +}; + +#if __has_builtin(__builtin_coro_noop) +struct noop_coroutine_promise {}; + +template <> +class _LIBCPP_TEMPLATE_VIS coroutine_handle : public coroutine_handle<> { + using _Base = coroutine_handle<>; + using _Promise = noop_coroutine_promise; + +public: + _LIBCPP_INLINE_VISIBILITY + _Promise& promise() const { + return *static_cast<_Promise*>(__builtin_coro_promise(this->__handle_, _LIBCPP_ALIGNOF(_Promise), false)); + } + + _LIBCPP_CONSTEXPR explicit operator bool() const _NOEXCEPT { return true; } + _LIBCPP_CONSTEXPR bool done() const _NOEXCEPT { return false; } + + _LIBCPP_CONSTEXPR_AFTER_CXX17 void operator()() const _NOEXCEPT {} + _LIBCPP_CONSTEXPR_AFTER_CXX17 void resume() const _NOEXCEPT {} + _LIBCPP_CONSTEXPR_AFTER_CXX17 void destroy() const _NOEXCEPT {} + +private: + _LIBCPP_INLINE_VISIBILITY + friend coroutine_handle noop_coroutine() _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY coroutine_handle() _NOEXCEPT { this->__handle_ = __builtin_coro_noop(); } +}; + +using noop_coroutine_handle = coroutine_handle; + +inline _LIBCPP_INLINE_VISIBILITY noop_coroutine_handle noop_coroutine() _NOEXCEPT { return noop_coroutine_handle(); } +#endif // __has_builtin(__builtin_coro_noop) + +struct suspend_never { + _LIBCPP_INLINE_VISIBILITY + bool await_ready() const _NOEXCEPT { return true; } + _LIBCPP_INLINE_VISIBILITY + void await_suspend(coroutine_handle<>) const _NOEXCEPT {} + _LIBCPP_INLINE_VISIBILITY + void await_resume() const _NOEXCEPT {} +}; + +struct suspend_always { + _LIBCPP_INLINE_VISIBILITY + bool await_ready() const _NOEXCEPT { return false; } + _LIBCPP_INLINE_VISIBILITY + void await_suspend(coroutine_handle<>) const _NOEXCEPT {} + _LIBCPP_INLINE_VISIBILITY + void await_resume() const _NOEXCEPT {} +}; + +template +struct hash<_VSTD::coroutine_handle<_Tp> > { + using __arg_type = _VSTD::coroutine_handle<_Tp>; + _LIBCPP_INLINE_VISIBILITY + size_t operator()(__arg_type const& __v) const _NOEXCEPT { return hash()(__v.address()); } +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // !defined(_LIBCPP_HAS_NO_COROUTINES) + +#endif /* _LIBCPP_COROUTINE */ Index: libcxx/include/experimental/coroutine =================================================================== --- libcxx/include/experimental/coroutine +++ libcxx/include/experimental/coroutine @@ -69,6 +69,14 @@ _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_COROUTINES +#if defined(_LIBCPP_WARNING) +_LIBCPP_WARNING(" is deprecated and would like" + " to be removed in following versions. " + "Please include instead.") +#else +# warning is deprecated and would like to be removed in following versions. Please include instead. +#endif + template struct __coroutine_traits_sfinae {}; Index: libcxx/include/module.modulemap =================================================================== --- libcxx/include/module.modulemap +++ libcxx/include/module.modulemap @@ -849,7 +849,7 @@ } module coroutine { requires coroutines - header "experimental/coroutine" + header "coroutine" export * } module deque { Index: libcxx/test/libcxx/double_include.sh.cpp =================================================================== --- libcxx/test/libcxx/double_include.sh.cpp +++ libcxx/test/libcxx/double_include.sh.cpp @@ -63,6 +63,9 @@ #include #include #include +#if defined(__cpp_coroutines) +# include +#endif #include #include #include @@ -198,9 +201,6 @@ // experimental headers #if __cplusplus >= 201103L # include -# if defined(__cpp_coroutines) -# include -# endif # include # ifndef _LIBCPP_HAS_NO_FILESYSTEM_LIBRARY # include Index: libcxx/test/libcxx/language.support/support.coroutines/dialect_support.pass.cpp =================================================================== --- libcxx/test/libcxx/language.support/support.coroutines/dialect_support.pass.cpp +++ libcxx/test/libcxx/language.support/support.coroutines/dialect_support.pass.cpp @@ -10,25 +10,23 @@ // REQUIRES: fcoroutines-ts // ADDITIONAL_COMPILE_FLAGS: -fcoroutines-ts -// A simple "breathing" test that checks that +// A simple "breathing" test that checks that // can be parsed and used in all dialects, including C++03 in order to match // Clang's behavior. -#include +#include #include "test_macros.h" -namespace coro = std::experimental::coroutines_v1; - -coro::suspend_always sa; -coro::suspend_never sn; +std::suspend_always sa; +std::suspend_never sn; struct MyFuture { struct promise_type { - typedef coro::coroutine_handle HandleT; - coro::suspend_never initial_suspend() { return sn; } - coro::suspend_always final_suspend() TEST_NOEXCEPT { return sa; } - coro::suspend_never yield_value(int) { return sn; } + typedef std::coroutine_handle HandleT; + std::suspend_never initial_suspend() { return sn; } + std::suspend_always final_suspend() TEST_NOEXCEPT { return sa; } + std::suspend_never yield_value(int) { return sn; } MyFuture get_return_object() { MyFuture f(HandleT::from_promise(*this)); return f; @@ -40,7 +38,7 @@ MyFuture() : p() {} MyFuture(HandleT h) : p(h) {} - coro::coroutine_handle p; + std::coroutine_handle p; }; MyFuture test_coro() { @@ -49,8 +47,7 @@ co_return; } -int main(int, char**) -{ +int main(int, char**) { MyFuture f = test_coro(); while (!f.p.done()) f.p.resume(); Index: libcxx/test/libcxx/language.support/support.coroutines/version.pass.cpp =================================================================== --- libcxx/test/libcxx/language.support/support.coroutines/version.pass.cpp +++ libcxx/test/libcxx/language.support/support.coroutines/version.pass.cpp @@ -11,14 +11,10 @@ // REQUIRES: fcoroutines-ts // ADDITIONAL_COMPILE_FLAGS: -fcoroutines-ts -#include +#include #ifndef _LIBCPP_VERSION #error _LIBCPP_VERSION must be defined #endif -int main(int, char**) -{ - - return 0; -} +int main(int, char**) { return 0; } Index: libcxx/test/libcxx/min_max_macros.compile.pass.cpp =================================================================== --- libcxx/test/libcxx/min_max_macros.compile.pass.cpp +++ libcxx/test/libcxx/min_max_macros.compile.pass.cpp @@ -89,6 +89,10 @@ TEST_MACROS(); #include TEST_MACROS(); +#if defined(__cpp_coroutines) +# include +TEST_MACROS(); +#endif #include TEST_MACROS(); #include @@ -314,10 +318,6 @@ #if __cplusplus >= 201103L # include TEST_MACROS(); -# if defined(__cpp_coroutines) -# include -TEST_MACROS(); -# endif # include TEST_MACROS(); # ifndef _LIBCPP_HAS_NO_FILESYSTEM_LIBRARY Index: libcxx/test/libcxx/no_assert_include.compile.pass.cpp =================================================================== --- libcxx/test/libcxx/no_assert_include.compile.pass.cpp +++ libcxx/test/libcxx/no_assert_include.compile.pass.cpp @@ -58,6 +58,9 @@ #include #include #include +#if defined(__cpp_coroutines) +# include +#endif #include #include #include @@ -193,9 +196,6 @@ // experimental headers #if __cplusplus >= 201103L # include -# if defined(__cpp_coroutines) -# include -# endif # include # ifndef _LIBCPP_HAS_NO_FILESYSTEM_LIBRARY # include Index: libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.hash/hash.pass.cpp =================================================================== --- libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.hash/hash.pass.cpp +++ libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.hash/hash.pass.cpp @@ -9,16 +9,16 @@ // UNSUPPORTED: c++03, c++11 -// +// // template // struct coroutine_handle; // namespace std { -// template struct hash>; +// template struct hash>; // } -#include +#include #include #include #include @@ -27,8 +27,6 @@ #include "test_macros.h" -namespace coro = std::experimental; - template void do_test(uintptr_t LHSVal, uintptr_t RHSVal) { const size_t ExpectLHS = std::hash{}(reinterpret_cast(LHSVal)); @@ -47,17 +45,11 @@ } } -int main(int, char**) -{ - std::pair const TestCases[] = { - {0, 0}, - {0, 8}, - {8, 8}, - {8, 16} - }; +int main(int, char**) { + std::pair const TestCases[] = {{0, 0}, {0, 8}, {8, 8}, {8, 16}}; for (auto& TC : TestCases) { - do_test>(TC.first, TC.second); - do_test>(TC.first, TC.second); + do_test >(TC.first, TC.second); + do_test >(TC.first, TC.second); } return 0; Index: libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.capacity/operator_bool.pass.cpp =================================================================== --- libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.capacity/operator_bool.pass.cpp +++ libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.capacity/operator_bool.pass.cpp @@ -9,31 +9,31 @@ // UNSUPPORTED: c++03, c++11 -// +// // template // struct coroutine_handle; // constexpr explicit operator bool() const noexcept -#include +#include #include #include #include "test_macros.h" -namespace coro = std::experimental; - template void do_test() { static_assert(std::is_nothrow_constructible::value, ""); static_assert(!std::is_convertible::value, ""); { - constexpr C c; ((void)c); + constexpr C c; + ((void)c); static_assert(bool(c) == false, ""); } { // null case - const C c = {}; ((void)c); + const C c = {}; + ((void)c); ASSERT_NOEXCEPT(bool(c)); if (c) assert(false); @@ -50,10 +50,9 @@ } } -int main(int, char**) -{ - do_test>(); - do_test>(); +int main(int, char**) { + do_test >(); + do_test >(); return 0; } Index: libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.compare/equal_comp.pass.cpp =================================================================== --- libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.compare/equal_comp.pass.cpp +++ libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.compare/equal_comp.pass.cpp @@ -9,7 +9,7 @@ // UNSUPPORTED: c++03, c++11 -// +// // template // struct coroutine_handle; @@ -17,7 +17,7 @@ // bool operator==(coroutine_handle<>, coroutine_handle<>) noexcept // bool operator!=(coroutine_handle<>, coroutine_handle<>) noexcept -#include +#include #include #include #include @@ -25,8 +25,6 @@ #include "test_macros.h" -namespace coro = std::experimental; - template void do_test(uintptr_t LHSVal, uintptr_t RHSVal) { const C LHS = C::from_address(reinterpret_cast(LHSVal)); @@ -44,17 +42,11 @@ } } -int main(int, char**) -{ - std::pair const TestCases[] = { - {0, 0}, - {16, 16}, - {0, 16}, - {16, 0} - }; +int main(int, char**) { + std::pair const TestCases[] = {{0, 0}, {16, 16}, {0, 16}, {16, 0}}; for (auto& TC : TestCases) { - do_test>(TC.first, TC.second); - do_test>(TC.first, TC.second); + do_test >(TC.first, TC.second); + do_test >(TC.first, TC.second); } return 0; Index: libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.compare/less_comp.pass.cpp =================================================================== --- libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.compare/less_comp.pass.cpp +++ libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.compare/less_comp.pass.cpp @@ -9,7 +9,7 @@ // UNSUPPORTED: c++03, c++11 -// +// // template // struct coroutine_handle; @@ -19,7 +19,7 @@ // bool operator>=(coroutine_handle<>, coroutine_handle<>) noexcept // bool operator<=(coroutine_handle<>, coroutine_handle<>) noexcept -#include +#include #include #include #include @@ -27,8 +27,6 @@ #include "test_macros.h" -namespace coro = std::experimental; - template void do_test(uintptr_t LHSVal, uintptr_t RHSVal) { const C LHS = C::from_address(reinterpret_cast(LHSVal)); @@ -53,17 +51,11 @@ } } -int main(int, char**) -{ - std::pair const TestCases[] = { - {0, 0}, - {16, 16}, - {0, 16}, - {16, 0} - }; +int main(int, char**) { + std::pair const TestCases[] = {{0, 0}, {16, 16}, {0, 16}, {16, 0}}; for (auto& TC : TestCases) { - do_test>(TC.first, TC.second); - do_test>(TC.first, TC.second); + do_test >(TC.first, TC.second); + do_test >(TC.first, TC.second); } return 0; Index: libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.completion/done.pass.cpp =================================================================== --- libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.completion/done.pass.cpp +++ libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.completion/done.pass.cpp @@ -9,14 +9,14 @@ // UNSUPPORTED: c++03, c++11 -// +// // template // struct coroutine_handle; // bool done() const -#include +#include #include #include #include @@ -25,10 +25,8 @@ #include "test_macros.h" -namespace coro = std::experimental; - template -void do_test(coro::coroutine_handle const& H) { +void do_test(std::coroutine_handle const& H) { // FIXME Add a runtime test { ASSERT_SAME_TYPE(decltype(H.done()), bool); @@ -36,10 +34,9 @@ } } -int main(int, char**) -{ - do_test(coro::coroutine_handle<>{}); - do_test(coro::coroutine_handle{}); +int main(int, char**) { + do_test(std::coroutine_handle<>{}); + do_test(std::coroutine_handle{}); return 0; } Index: libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.con/assign.pass.cpp =================================================================== --- libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.con/assign.pass.cpp +++ libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.con/assign.pass.cpp @@ -9,27 +9,26 @@ // UNSUPPORTED: c++03, c++11 -// +// // template // struct coroutine_handle; // coroutine_handle& operator=(nullptr_t) noexcept -#include +#include #include #include #include "test_macros.h" -namespace coro = std::experimental; - template void do_test() { int dummy = 42; void* dummy_h = &dummy; { - C c; ((void)c); + C c; + ((void)c); static_assert(std::is_nothrow_assignable::value, ""); static_assert(!std::is_assignable::value, ""); } @@ -48,10 +47,9 @@ } } -int main(int, char**) -{ - do_test>(); - do_test>(); +int main(int, char**) { + do_test >(); + do_test >(); return 0; } Index: libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.con/construct.pass.cpp =================================================================== --- libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.con/construct.pass.cpp +++ libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.con/construct.pass.cpp @@ -9,7 +9,7 @@ // UNSUPPORTED: c++03, c++11 -// +// // template // struct coroutine_handle; @@ -17,14 +17,12 @@ // constexpr coroutine_handle() noexcept // constexpr coroutine_handle(nullptr_t) noexcept -#include +#include #include #include #include "test_macros.h" -namespace coro = std::experimental; - template void do_test() { { @@ -47,10 +45,9 @@ } } -int main(int, char**) -{ - do_test>(); - do_test>(); +int main(int, char**) { + do_test >(); + do_test >(); return 0; } Index: libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.export/address.pass.cpp =================================================================== --- libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.export/address.pass.cpp +++ libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.export/address.pass.cpp @@ -9,29 +9,29 @@ // UNSUPPORTED: c++03, c++11 -// +// // template // struct coroutine_handle; // constexpr void* address() const noexcept -#include +#include #include #include #include "test_macros.h" -namespace coro = std::experimental; - template void do_test() { { - constexpr C c; ((void)c); + constexpr C c; + ((void)c); static_assert(c.address() == nullptr, ""); } { - const C c = {}; ((void)c); + const C c = {}; + ((void)c); ASSERT_NOEXCEPT(c.address()); ASSERT_SAME_TYPE(decltype(c.address()), void*); assert(c.address() == nullptr); @@ -43,10 +43,9 @@ } } -int main(int, char**) -{ - do_test>(); - do_test>(); +int main(int, char**) { + do_test >(); + do_test >(); return 0; } Index: libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.export/from_address.fail.cpp =================================================================== --- libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.export/from_address.fail.cpp +++ libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.export/from_address.fail.cpp @@ -8,7 +8,7 @@ //===----------------------------------------------------------------------===// // UNSUPPORTED: c++03, c++11 -// +// // template // struct coroutine_handle; @@ -20,26 +20,23 @@ // FIXME: This behavior is an extension, and should upstreamed into the TS or // the test removed if the TS changes are rejected. -#include +#include #include #include -namespace coro = std::experimental; - -int main(int, char**) -{ +int main(int, char**) { { - using H = coro::coroutine_handle<>; - // expected-error@experimental/coroutine:* 3 {{coroutine_handle::from_address cannot be called with non-void pointers}} - H::from_address((int*)nullptr); // expected-note {{requested here}} + using H = std::coroutine_handle<>; + // expected-error@coroutine:* 3 {{coroutine_handle::from_address cannot be called with non-void pointers}} + H::from_address((int*)nullptr); // expected-note {{requested here}} H::from_address((const void*)nullptr); // expected-note {{requested here}} H::from_address((const char*)nullptr); // expected-note {{requested here}} } { - using H = coro::coroutine_handle; - // expected-error@experimental/coroutine:* 1 {{static_assert failed "coroutine_handle::from_address cannot be used with pointers to the coroutine's promise type; use 'from_promise' instead"}} + using H = std::coroutine_handle; + // expected-error@coroutine:* 1 {{static_assert failed "coroutine_handle::from_address cannot be used with pointers to the coroutine's promise type; use 'from_promise' instead"}} H::from_address((const char*)nullptr); // expected-note {{requested here}} - // expected-error@experimental/coroutine:* 1 {{coroutine_handle::from_address cannot be called with non-void pointers}} + // expected-error@coroutine:* 1 {{coroutine_handle::from_address cannot be called with non-void pointers}} H::from_address((int*)nullptr); // expected-note {{requested here}} } Index: libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.export/from_address.pass.cpp =================================================================== --- libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.export/from_address.pass.cpp +++ libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.export/from_address.pass.cpp @@ -9,21 +9,19 @@ // UNSUPPORTED: c++03, c++11 -// +// // template // struct coroutine_handle; // static coroutine_handle from_address(void*) noexcept -#include +#include #include #include #include "test_macros.h" -namespace coro = std::experimental; - template void do_test() { { @@ -40,10 +38,9 @@ } } -int main(int, char**) -{ - do_test>(); - do_test>(); +int main(int, char**) { + do_test >(); + do_test >(); return 0; } Index: libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.noop/noop_coroutine.pass.cpp =================================================================== --- libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.noop/noop_coroutine.pass.cpp +++ libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.noop/noop_coroutine.pass.cpp @@ -10,12 +10,12 @@ // UNSUPPORTED: c++03, c++11 // UNSUPPORTED: ubsan -// +// // struct noop_coroutine_promise; // using noop_coroutine_handle = coroutine_handle; // noop_coroutine_handle noop_coroutine() noexcept; -#include +#include #include #include @@ -23,11 +23,8 @@ #if __has_builtin(__builtin_coro_noop) -namespace coro = std::experimental::coroutines_v1; - - -static_assert(std::is_same, coro::noop_coroutine_handle>::value, ""); -static_assert(std::is_same::value, ""); +static_assert(std::is_same, std::noop_coroutine_handle>::value, ""); +static_assert(std::is_same::value, ""); // template <> struct coroutine_handle : coroutine_handle<> // { @@ -46,10 +43,9 @@ // // 18.11.2.10 noop address // constexpr void* address() const noexcept; -int main(int, char**) -{ - auto h = coro::noop_coroutine(); - coro::coroutine_handle<> base = h; +int main(int, char**) { + auto h = std::noop_coroutine(); + std::coroutine_handle<> base = h; assert(h); assert(base); @@ -66,7 +62,7 @@ h.promise(); assert(h.address() == base.address()); assert(h.address() != nullptr); - assert(coro::coroutine_handle<>::from_address(h.address()) == base); + assert(std::coroutine_handle<>::from_address(h.address()) == base); return 0; } Index: libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.prom/promise.pass.cpp =================================================================== --- libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.prom/promise.pass.cpp +++ libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.prom/promise.pass.cpp @@ -9,14 +9,14 @@ // UNSUPPORTED: c++03, c++11 -// +// // template // struct coroutine_handle; // Promise& promise() const -#include +#include #include #include #include @@ -25,14 +25,12 @@ #include "test_macros.h" -namespace coro = std::experimental; - struct MyCoro { struct promise_type { void unhandled_exception() {} void return_void() {} - coro::suspend_never initial_suspend() { return {}; } - coro::suspend_never final_suspend() noexcept { return {}; } + std::suspend_never initial_suspend() { return {}; } + std::suspend_never final_suspend() noexcept { return {}; } MyCoro get_return_object() { do_runtime_test(); return {}; @@ -41,9 +39,9 @@ // Test that a coroutine_handle can be created from a const // promise_type and that it represents the same coroutine as // coroutine_handle - using CH = coro::coroutine_handle; - using CCH = coro::coroutine_handle; - const auto &cthis = *this; + using CH = std::coroutine_handle; + using CCH = std::coroutine_handle; + const auto& cthis = *this; CH h = CH::from_promise(*this); CCH h2 = CCH::from_promise(*this); CCH h3 = CCH::from_promise(cthis); @@ -56,12 +54,10 @@ }; }; -MyCoro do_runtime_test() { - co_await coro::suspend_never{}; -} +MyCoro do_runtime_test() { co_await std::suspend_never{}; } template -void do_test(coro::coroutine_handle&& H) { +void do_test(std::coroutine_handle&& H) { // FIXME Add a runtime test { @@ -75,10 +71,9 @@ } } -int main(int, char**) -{ - do_test(coro::coroutine_handle{}); - do_test(coro::coroutine_handle{}); +int main(int, char**) { + do_test(std::coroutine_handle{}); + do_test(std::coroutine_handle{}); do_runtime_test(); return 0; Index: libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.resumption/destroy.pass.cpp =================================================================== --- libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.resumption/destroy.pass.cpp +++ libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.resumption/destroy.pass.cpp @@ -9,14 +9,14 @@ // UNSUPPORTED: c++03, c++11 -// +// // template // struct coroutine_handle; // void destroy() -#include +#include #include #include #include @@ -25,8 +25,6 @@ #include "test_macros.h" -namespace coro = std::experimental; - template auto has_destroy_imp(H&& h, int) -> decltype(h.destroy(), std::true_type{}); template @@ -38,8 +36,8 @@ } template -void do_test(coro::coroutine_handle&& H) { - using HType = coro::coroutine_handle; +void do_test(std::coroutine_handle&& H) { + using HType = std::coroutine_handle; // FIXME Add a runtime test { ASSERT_SAME_TYPE(decltype(H.destroy()), void); @@ -53,10 +51,9 @@ } } -int main(int, char**) -{ - do_test(coro::coroutine_handle<>{}); - do_test(coro::coroutine_handle{}); +int main(int, char**) { + do_test(std::coroutine_handle<>{}); + do_test(std::coroutine_handle{}); return 0; } Index: libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.resumption/resume.pass.cpp =================================================================== --- libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.resumption/resume.pass.cpp +++ libcxx/test/std/language.support/support.coroutines/coroutine.handle/coroutine.handle.resumption/resume.pass.cpp @@ -9,7 +9,7 @@ // UNSUPPORTED: c++03, c++11 -// +// // template // struct coroutine_handle; @@ -17,7 +17,7 @@ // void operator()() // void resume() -#include +#include #include #include #include @@ -26,9 +26,6 @@ #include "test_macros.h" -namespace coro = std::experimental; - - template auto has_resume_imp(H&& h, int) -> decltype(h.resume(), std::true_type{}); template @@ -39,7 +36,6 @@ return decltype(has_resume_imp(std::declval(), 0))::value; } - template auto has_call_operator_imp(H&& h, int) -> decltype(h(), std::true_type{}); template @@ -51,8 +47,8 @@ } template -void do_test(coro::coroutine_handle&& H) { - using HType = coro::coroutine_handle; +void do_test(std::coroutine_handle&& H) { + using HType = std::coroutine_handle; // FIXME Add a runtime test { ASSERT_SAME_TYPE(decltype(H.resume()), void); @@ -72,10 +68,9 @@ } } -int main(int, char**) -{ - do_test(coro::coroutine_handle<>{}); - do_test(coro::coroutine_handle{}); +int main(int, char**) { + do_test(std::coroutine_handle<>{}); + do_test(std::coroutine_handle{}); return 0; } Index: libcxx/test/std/language.support/support.coroutines/coroutine.handle/void_handle.pass.cpp =================================================================== --- libcxx/test/std/language.support/support.coroutines/coroutine.handle/void_handle.pass.cpp +++ libcxx/test/std/language.support/support.coroutines/coroutine.handle/void_handle.pass.cpp @@ -9,12 +9,10 @@ // UNSUPPORTED: c++03, c++11 -#include +#include #include "test_macros.h" -namespace coro = std::experimental; - struct A { using promise_type = A*; }; @@ -22,29 +20,28 @@ struct B {}; struct C {}; -namespace std { namespace experimental { - template <> - struct coroutine_traits<::A, int> { - using promise_type = int*; - }; - template - struct coroutine_traits<::B, Args...> { - using promise_type = B*; - }; - template <> - struct coroutine_traits<::C> { - using promise_type = void; - }; -}} - -template +namespace std { +template <> +struct coroutine_traits< ::A, int> { + using promise_type = int*; +}; +template +struct coroutine_traits< ::B, Args...> { + using promise_type = B*; +}; +template <> +struct coroutine_traits< ::C> { + using promise_type = void; +}; +} // namespace std + +template void check_type() { - using P = typename coro::coroutine_traits::promise_type ; + using P = typename std::coroutine_traits::promise_type; static_assert(std::is_same::value, ""); }; -int main(int, char**) -{ +int main(int, char**) { check_type(); check_type(); check_type(); Index: libcxx/test/std/language.support/support.coroutines/coroutine.traits/promise_type.pass.cpp =================================================================== --- libcxx/test/std/language.support/support.coroutines/coroutine.traits/promise_type.pass.cpp +++ libcxx/test/std/language.support/support.coroutines/coroutine.traits/promise_type.pass.cpp @@ -9,18 +9,22 @@ // UNSUPPORTED: c++03, c++11 -#include +#include #include "test_macros.h" -namespace coro = std::experimental; - template -constexpr bool has_promise_type(int) { return true; } +constexpr bool has_promise_type(int) { + return true; +} template -constexpr bool has_promise_type(long) { return false; } +constexpr bool has_promise_type(long) { + return false; +} template -constexpr bool has_promise_type() { return has_promise_type(0); } +constexpr bool has_promise_type() { + return has_promise_type(0); +} struct A { using promise_type = A*; @@ -34,36 +38,35 @@ }; struct E {}; -namespace std { namespace experimental { - template <> - struct coroutine_traits<::A, int> { - using promise_type = int*; - }; - template - struct coroutine_traits<::B, Args...> { - using promise_type = B*; - }; - template <> - struct coroutine_traits<::C> { - using promise_type = void; - }; -}} +namespace std { +template <> +struct coroutine_traits< ::A, int> { + using promise_type = int*; +}; +template +struct coroutine_traits< ::B, Args...> { + using promise_type = B*; +}; +template <> +struct coroutine_traits< ::C> { + using promise_type = void; +}; +} // namespace std -template +template void check_type() { - using Traits = coro::coroutine_traits; + using Traits = std::coroutine_traits; static_assert(has_promise_type(), ""); static_assert(std::is_same::value, ""); } -template +template void check_no_type() { - using Traits = coro::coroutine_traits; + using Traits = std::coroutine_traits; static_assert(!has_promise_type(), ""); } -int main(int, char**) -{ +int main(int, char**) { { check_type(); check_type(); Index: libcxx/test/std/language.support/support.coroutines/coroutine.trivial.awaitables/suspend_always.pass.cpp =================================================================== --- libcxx/test/std/language.support/support.coroutines/coroutine.trivial.awaitables/suspend_always.pass.cpp +++ libcxx/test/std/language.support/support.coroutines/coroutine.trivial.awaitables/suspend_always.pass.cpp @@ -9,31 +9,30 @@ // UNSUPPORTED: c++03, c++11 -#include +#include #include #include #include "test_macros.h" -namespace coro = std::experimental; - -using SuspendT = std::experimental::coroutines_v1::suspend_always; +using SuspendT = std::suspend_always; TEST_SAFE_STATIC SuspendT safe_sa; constexpr SuspendT constexpr_sa; constexpr bool check_suspend_constexpr() { SuspendT s{}; - const SuspendT scopy(s); ((void)scopy); - SuspendT smove(std::move(s)); ((void)smove); + const SuspendT scopy(s); + ((void)scopy); + SuspendT smove(std::move(s)); + ((void)smove); s = scopy; s = std::move(smove); return true; } -int main(int, char**) -{ - using H = coro::coroutine_handle<>; +int main(int, char**) { + using H = std::coroutine_handle<>; using S = SuspendT; H h{}; S s{}; Index: libcxx/test/std/language.support/support.coroutines/coroutine.trivial.awaitables/suspend_never.pass.cpp =================================================================== --- libcxx/test/std/language.support/support.coroutines/coroutine.trivial.awaitables/suspend_never.pass.cpp +++ libcxx/test/std/language.support/support.coroutines/coroutine.trivial.awaitables/suspend_never.pass.cpp @@ -9,33 +9,31 @@ // UNSUPPORTED: c++03, c++11 -#include +#include #include #include #include "test_macros.h" -namespace coro = std::experimental; - // Test that the type is in the correct namespace -using SuspendT = std::experimental::coroutines_v1::suspend_never; +using SuspendT = std::suspend_never; TEST_SAFE_STATIC SuspendT safe_sn; constexpr SuspendT constexpr_sn; constexpr bool check_suspend_constexpr() { SuspendT s{}; - const SuspendT scopy(s); ((void)scopy); - SuspendT smove(std::move(s)); ((void)smove); + const SuspendT scopy(s); + ((void)scopy); + SuspendT smove(std::move(s)); + ((void)smove); s = scopy; s = std::move(smove); return true; } - -int main(int, char**) -{ - using H = coro::coroutine_handle<>; +int main(int, char**) { + using H = std::coroutine_handle<>; using S = SuspendT; H h{}; S s{}; Index: libcxx/test/std/language.support/support.coroutines/end.to.end/await_result.pass.cpp =================================================================== --- libcxx/test/std/language.support/support.coroutines/end.to.end/await_result.pass.cpp +++ libcxx/test/std/language.support/support.coroutines/end.to.end/await_result.pass.cpp @@ -9,12 +9,12 @@ // UNSUPPORTED: c++03, c++11 -#include +#include #include #include "test_macros.h" -using namespace std::experimental; +using namespace std; struct coro_t { struct promise_type { @@ -33,21 +33,20 @@ ~B() {} bool await_ready() { return true; } B await_resume() { return {}; } - template void await_suspend(F) {} + template + void await_suspend(F) {} }; - struct A { ~A() {} bool await_ready() { return true; } int await_resume() { return 42; } - template void await_suspend(F) {} + template + void await_suspend(F) {} }; int last_value = -1; -void set_value(int x) { - last_value = x; -} +void set_value(int x) { last_value = x; } coro_t f(int n) { if (n == 0) { Index: libcxx/test/std/language.support/support.coroutines/end.to.end/bool_await_suspend.pass.cpp =================================================================== --- libcxx/test/std/language.support/support.coroutines/end.to.end/bool_await_suspend.pass.cpp +++ libcxx/test/std/language.support/support.coroutines/end.to.end/bool_await_suspend.pass.cpp @@ -12,18 +12,16 @@ // See https://llvm.org/PR33271 // UNSUPPORTED: ubsan -#include +#include #include #include "test_macros.h" -using namespace std::experimental; +using namespace std; struct coro_t { struct promise_type { - coro_t get_return_object() { - return coroutine_handle::from_promise(*this); - } + coro_t get_return_object() { return coroutine_handle::from_promise(*this); } suspend_never initial_suspend() { return {}; } suspend_never final_suspend() noexcept { return {}; } void return_void() {} @@ -36,13 +34,19 @@ struct NoSuspend { bool await_ready() { return false; } void await_resume() {} - template bool await_suspend(F) { return false; } + template + bool await_suspend(F) { + return false; + } }; struct DoSuspend { bool await_ready() { return false; } void await_resume() {} - template bool await_suspend(F) { return true; } + template + bool await_suspend(F) { + return true; + } }; bool f_started, f_resumed = false; Index: libcxx/test/std/language.support/support.coroutines/end.to.end/expected.pass.cpp =================================================================== --- libcxx/test/std/language.support/support.coroutines/end.to.end/expected.pass.cpp +++ libcxx/test/std/language.support/support.coroutines/end.to.end/expected.pass.cpp @@ -9,21 +9,21 @@ // UNSUPPORTED: c++03, c++11 -#include +#include #include #include #include "test_macros.h" -using namespace std::experimental; +using namespace std; -struct error_tag { }; +struct error_tag {}; template struct expected { struct Data { - Data() : val(), error() { } - Data(T v, Error e) : val(v), error(e) { } + Data() : val(), error() {} + Data(T v, Error e) : val(v), error(e) {} T val; Error error; }; @@ -35,10 +35,16 @@ struct promise_type { std::shared_ptr data; - expected get_return_object() { data = std::make_shared(); return {data}; } + expected get_return_object() { + data = std::make_shared(); + return {data}; + } suspend_never initial_suspend() { return {}; } suspend_never final_suspend() noexcept { return {}; } - void return_value(T v) { data->val = v; data->error = {}; } + void return_value(T v) { + data->val = v; + data->error = {}; + } void unhandled_exception() {} }; Index: libcxx/test/std/language.support/support.coroutines/end.to.end/fullexpr-dtor.pass.cpp =================================================================== --- libcxx/test/std/language.support/support.coroutines/end.to.end/fullexpr-dtor.pass.cpp +++ libcxx/test/std/language.support/support.coroutines/end.to.end/fullexpr-dtor.pass.cpp @@ -9,12 +9,12 @@ // UNSUPPORTED: c++03, c++11 -#include +#include #include #include "test_macros.h" -using namespace std::experimental; +using namespace std; int alive = 0; int ctor_called = 0; @@ -26,8 +26,14 @@ dtor_called = 0; } struct Noisy { - Noisy() { ++alive; ++ctor_called; } - ~Noisy() { --alive; ++dtor_called; } + Noisy() { + ++alive; + ++ctor_called; + } + ~Noisy() { + --alive; + ++dtor_called; + } #if TEST_STD_VER > 14 Noisy(Noisy const&) = delete; #else @@ -39,14 +45,14 @@ struct Bug { bool await_ready() { return true; } - void await_suspend(std::experimental::coroutine_handle<>) {} + void await_suspend(std::coroutine_handle<>) {} Noisy await_resume() { return {}; } }; struct coro2 { struct promise_type { - suspend_never initial_suspend() { return{}; } + suspend_never initial_suspend() { return {}; } suspend_never final_suspend() noexcept { return {}; } - coro2 get_return_object() { return{}; } + coro2 get_return_object() { return {}; } void return_void() {} Bug yield_value(int) { return {}; } void unhandled_exception() {} @@ -79,7 +85,6 @@ assert(ctor_called == 1); assert(dtor_called == 1); assert(alive == 0); - } coro2 c() { Index: libcxx/test/std/language.support/support.coroutines/end.to.end/generator.pass.cpp =================================================================== --- libcxx/test/std/language.support/support.coroutines/end.to.end/generator.pass.cpp +++ libcxx/test/std/language.support/support.coroutines/end.to.end/generator.pass.cpp @@ -12,14 +12,14 @@ // See https://llvm.org/PR33271 // UNSUPPORTED: ubsan -#include +#include #include #include #include "test_macros.h" #include "coroutine_types.h" -using namespace std::experimental; +using namespace std; struct minig { struct promise_type { @@ -41,7 +41,7 @@ } int current_value() { return p.promise().current_value; } - minig(minig &&rhs) : p(rhs.p) { rhs.p = nullptr; } + minig(minig&& rhs) : p(rhs.p) { rhs.p = nullptr; } ~minig() { if (p) @@ -49,13 +49,11 @@ } private: - explicit minig(promise_type *p) - : p(coroutine_handle::from_promise(*p)) {} + explicit minig(promise_type* p) : p(coroutine_handle::from_promise(*p)) {} coroutine_handle p; }; - minig mini_count(int n) { for (int i = 0; i < n; i++) { co_yield i; @@ -82,16 +80,16 @@ void test_range() { int sum = 0; - for (auto v: range(1, 20)) - sum += v; - assert(sum == 190); + for (auto v : range(1, 20)) + sum += v; + assert(sum == 190); } void test_mini_generator() { int sum = 0; auto g = mini_count(5); while (g.move_next()) { - sum += g.current_value(); + sum += g.current_value(); } assert(sum == 10); } Index: libcxx/test/std/language.support/support.coroutines/end.to.end/go.pass.cpp =================================================================== --- libcxx/test/std/language.support/support.coroutines/end.to.end/go.pass.cpp +++ libcxx/test/std/language.support/support.coroutines/end.to.end/go.pass.cpp @@ -9,23 +9,21 @@ // UNSUPPORTED: c++03, c++11 -#include +#include #include #include "test_macros.h" -using namespace std::experimental; +using namespace std; bool cancel = false; -struct goroutine -{ +struct goroutine { static int const N = 10; static int count; static coroutine_handle<> stack[N]; - static void schedule(coroutine_handle<>& rh) - { + static void schedule(coroutine_handle<>& rh) { assert(count < N); stack[count++] = rh; rh = nullptr; @@ -35,22 +33,16 @@ static void go(goroutine) {} - static void run_one() - { + static void run_one() { assert(count > 0); stack[--count](); } - struct promise_type - { - suspend_never initial_suspend() { - return {}; - } + struct promise_type { + suspend_never initial_suspend() { return {}; } suspend_never final_suspend() noexcept { return {}; } void return_void() {} - goroutine get_return_object() { - return{}; - } + goroutine get_return_object() { return {}; } void unhandled_exception() {} }; }; @@ -63,21 +55,20 @@ struct push_awaiter { channel* ch; - bool await_ready() {return false; } + bool await_ready() { return false; } void await_suspend(coroutine_handle<> rh); void await_resume() {} }; struct pull_awaiter { - channel * ch; + channel* ch; bool await_ready(); void await_suspend(coroutine_handle<> rh); int await_resume(); }; -class channel -{ +class channel { using T = int; friend struct push_awaiter; @@ -86,25 +77,23 @@ T const* pvalue = nullptr; coroutine_handle<> reader = nullptr; coroutine_handle<> writer = nullptr; + public: - push_awaiter push(T const& value) - { + push_awaiter push(T const& value) { assert(pvalue == nullptr); assert(!writer); pvalue = &value; - return { this }; + return {this}; } - pull_awaiter pull() - { + pull_awaiter pull() { assert(!reader); - return { this }; + return {this}; } - void sync_push(T const& value) - { + void sync_push(T const& value) { assert(!pvalue); pvalue = &value; assert(reader); @@ -113,13 +102,12 @@ reader = nullptr; } - auto sync_pull() - { - while (!pvalue) goroutine::run_one(); + auto sync_pull() { + while (!pvalue) + goroutine::run_one(); auto result = *pvalue; pvalue = nullptr; - if (writer) - { + if (writer) { auto wr = writer; writer = nullptr; wr(); @@ -128,19 +116,14 @@ } }; -void push_awaiter::await_suspend(coroutine_handle<> rh) -{ +void push_awaiter::await_suspend(coroutine_handle<> rh) { ch->writer = rh; - if (ch->reader) goroutine::schedule(ch->reader); + if (ch->reader) + goroutine::schedule(ch->reader); } - -bool pull_awaiter::await_ready() { - return !!ch->writer; -} -void pull_awaiter::await_suspend(coroutine_handle<> rh) { - ch->reader = rh; -} +bool pull_awaiter::await_ready() { return !!ch->writer; } +void pull_awaiter::await_suspend(coroutine_handle<> rh) { ch->reader = rh; } int pull_awaiter::await_resume() { auto result = *ch->pvalue; ch->pvalue = nullptr; @@ -153,8 +136,7 @@ return result; } -goroutine pusher(channel& left, channel& right) -{ +goroutine pusher(channel& left, channel& right) { for (;;) { auto val = co_await left.pull(); co_await right.push(val + 1); Index: libcxx/test/std/language.support/support.coroutines/end.to.end/multishot_func.pass.cpp =================================================================== --- libcxx/test/std/language.support/support.coroutines/end.to.end/multishot_func.pass.cpp +++ libcxx/test/std/language.support/support.coroutines/end.to.end/multishot_func.pass.cpp @@ -9,17 +9,20 @@ // UNSUPPORTED: c++03, c++11 -#include +#include #include #include "test_macros.h" -using namespace std::experimental; +using namespace std; // This file tests, multishot, movable std::function like thing using coroutine // for compile-time type erasure and unerasure. -template struct func { - struct Input {R a, b;}; +template +struct func { + struct Input { + R a, b; + }; struct promise_type { Input* I; @@ -44,10 +47,10 @@ }; func() {} - func(func &&rhs) : h(rhs.h) { rhs.h = nullptr; } - func(func const &) = delete; + func(func&& rhs) : h(rhs.h) { rhs.h = nullptr; } + func(func const&) = delete; - func &operator=(func &&rhs) { + func& operator=(func&& rhs) { if (this != &rhs) { if (h) h.destroy(); @@ -57,13 +60,15 @@ return *this; } - template static func Create(F f) { + template + static func Create(F f) { for (;;) { co_yield f; } } - template func(F f) : func(Create(f)) {} + template + func(F f) : func(Create(f)) {} ~func() { if (h) @@ -71,8 +76,7 @@ } private: - func(promise_type *promise) - : h(coroutine_handle::from_promise(*promise)) {} + func(promise_type* promise) : h(coroutine_handle::from_promise(*promise)) {} coroutine_handle h; }; @@ -83,7 +87,7 @@ } int main(int, char**) { - int result = Do(1, 10, [](int a, int b) {return a + b;}); + int result = Do(1, 10, [](int a, int b) { return a + b; }); assert(result == 46); return 0; Index: libcxx/test/std/language.support/support.coroutines/end.to.end/oneshot_func.pass.cpp =================================================================== --- libcxx/test/std/language.support/support.coroutines/end.to.end/oneshot_func.pass.cpp +++ libcxx/test/std/language.support/support.coroutines/end.to.end/oneshot_func.pass.cpp @@ -9,18 +9,19 @@ // UNSUPPORTED: c++03, c++11 -#include +#include #include #include #include "test_macros.h" -using namespace std::experimental; +using namespace std; // This file tests, one shot, movable std::function like thing using coroutine // for compile-time type erasure and unerasure. -template struct func { +template +struct func { struct promise_type { R result; func get_return_object() { return {this}; } @@ -39,10 +40,10 @@ }; func() {} - func(func &&rhs) : h(rhs.h) { rhs.h = nullptr; } - func(func const &) = delete; + func(func&& rhs) : h(rhs.h) { rhs.h = nullptr; } + func(func const&) = delete; - func &operator=(func &&rhs) { + func& operator=(func&& rhs) { if (this != &rhs) { if (h) h.destroy(); @@ -52,9 +53,13 @@ return *this; } - template static func Create(F f) { co_return f(); } + template + static func Create(F f) { + co_return f(); + } - template func(F f) : func(Create(f)) {} + template + func(F f) : func(Create(f)) {} ~func() { if (h) @@ -62,14 +67,19 @@ } private: - func(promise_type *promise) - : h(coroutine_handle::from_promise(*promise)) {} + func(promise_type* promise) : h(coroutine_handle::from_promise(*promise)) {} coroutine_handle h; }; std::vector yielded_values = {}; -int yield(int x) { yielded_values.push_back(x); return x + 1; } -float fyield(int x) { yielded_values.push_back(x); return static_cast(x + 2); } +int yield(int x) { + yielded_values.push_back(x); + return x + 1; +} +float fyield(int x) { + yielded_values.push_back(x); + return static_cast(x + 2); +} void Do1(func f) { yield(f()); } void Do2(func f) { yield(static_cast(f())); } Index: libcxx/test/std/language.support/support.coroutines/includes.pass.cpp =================================================================== --- libcxx/test/std/language.support/support.coroutines/includes.pass.cpp +++ libcxx/test/std/language.support/support.coroutines/includes.pass.cpp @@ -9,11 +9,11 @@ // UNSUPPORTED: c++03, c++11 -// +// -// Test that includes +// Test that includes -#include +#include int main(int, char**) { // std::nothrow is not implicitly defined by the compiler when the include is Index: libcxx/test/std/language.support/support.limits/support.limits.general/coroutine.version.pass.cpp =================================================================== --- /dev/null +++ libcxx/test/std/language.support/support.limits/support.limits.general/coroutine.version.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// WARNING: This test was generated by generate_feature_test_macro_components.py +// and should not be edited manually. +// +// clang-format off + +// + +// Test the feature test macros defined by + +/* Constant Value + __cpp_lib_coroutine 201902L [C++20] +*/ + +#include +#include "test_macros.h" + +#if TEST_STD_VER < 14 + +# ifdef __cpp_lib_coroutine +# error "__cpp_lib_coroutine should not be defined before c++20" +# endif + +#elif TEST_STD_VER == 14 + +# ifdef __cpp_lib_coroutine +# error "__cpp_lib_coroutine should not be defined before c++20" +# endif + +#elif TEST_STD_VER == 17 + +# ifdef __cpp_lib_coroutine +# error "__cpp_lib_coroutine should not be defined before c++20" +# endif + +#elif TEST_STD_VER == 20 + +# if !defined(_LIBCPP_VERSION) +# ifndef __cpp_lib_coroutine +# error "__cpp_lib_coroutine should be defined in c++20" +# endif +# if __cpp_lib_coroutine != 201902L +# error "__cpp_lib_coroutine should have the value 201902L in c++20" +# endif +# else // _LIBCPP_VERSION +# ifdef __cpp_lib_coroutine +# error "__cpp_lib_coroutine should not be defined because it is unimplemented in libc++!" +# endif +# endif + +#elif TEST_STD_VER > 20 + +# if !defined(_LIBCPP_VERSION) +# ifndef __cpp_lib_coroutine +# error "__cpp_lib_coroutine should be defined in c++2b" +# endif +# if __cpp_lib_coroutine != 201902L +# error "__cpp_lib_coroutine should have the value 201902L in c++2b" +# endif +# else // _LIBCPP_VERSION +# ifdef __cpp_lib_coroutine +# error "__cpp_lib_coroutine should not be defined because it is unimplemented in libc++!" +# endif +# endif + +#endif // TEST_STD_VER > 20 + +int main(int, char**) { return 0; } Index: libcxx/test/support/coroutine_types.h =================================================================== --- libcxx/test/support/coroutine_types.h +++ libcxx/test/support/coroutine_types.h @@ -10,28 +10,27 @@ #ifndef SUPPORT_COROUTINE_TYPES_H #define SUPPORT_COROUTINE_TYPES_H -#include +#include template struct generator { struct promise_type { Ty current_value; - std::experimental::suspend_always yield_value(Ty value) { + std::suspend_always yield_value(Ty value) { this->current_value = value; return {}; } - std::experimental::suspend_always initial_suspend() { return {}; } - std::experimental::suspend_always final_suspend() noexcept { return {}; } + std::suspend_always initial_suspend() { return {}; } + std::suspend_always final_suspend() noexcept { return {}; } generator get_return_object() { return generator{this}; }; void return_void() {} void unhandled_exception() {} }; struct iterator { - std::experimental::coroutine_handle _Coro; + std::coroutine_handle _Coro; bool _Done; - iterator(std::experimental::coroutine_handle Coro, bool Done) - : _Coro(Coro), _Done(Done) {} + iterator(std::coroutine_handle Coro, bool Done) : _Coro(Coro), _Done(Done) {} iterator &operator++() { _Coro.resume(); @@ -65,10 +64,9 @@ } private: - explicit generator(promise_type *p) - : p(std::experimental::coroutine_handle::from_promise(*p)) {} + explicit generator(promise_type* p) : p(std::coroutine_handle::from_promise(*p)) {} - std::experimental::coroutine_handle p; + std::coroutine_handle p; }; #endif // SUPPORT_COROUTINE_TYPES_H Index: libcxx/utils/generate_header_tests.py =================================================================== --- libcxx/utils/generate_header_tests.py +++ libcxx/utils/generate_header_tests.py @@ -50,7 +50,7 @@ "streambuf": ["ifndef _LIBCPP_HAS_NO_LOCALIZATION"], "strstream": ["ifndef _LIBCPP_HAS_NO_LOCALIZATION"], - "experimental/coroutine": ["if defined(__cpp_coroutines)"], + "coroutine": ["if defined(__cpp_coroutines)"], "experimental/regex": ["ifndef _LIBCPP_HAS_NO_LOCALIZATION"], } Index: llvm/utils/gn/secondary/libcxx/include/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/libcxx/include/BUILD.gn +++ llvm/utils/gn/secondary/libcxx/include/BUILD.gn @@ -359,6 +359,7 @@ "ciso646", "climits", "clocale", + "coroutine", "cmath", "codecvt", "compare", @@ -387,7 +388,6 @@ "experimental/__config", "experimental/__memory", "experimental/algorithm", - "experimental/coroutine", "experimental/deque", "experimental/filesystem", "experimental/forward_list",