From 91e7a0ce34772c0f638dbd8d63c8eca3ae6a66b5 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Fri, 21 Aug 2020 08:45:44 -0700 Subject: [PATCH 1/3] promise types _must_ have unhandled_exception in C++20 .... even when `_CPPUNWIND` is not defined. --- stl/inc/experimental/generator | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stl/inc/experimental/generator b/stl/inc/experimental/generator index af54662c112..9ad1cb20937 100644 --- a/stl/inc/experimental/generator +++ b/stl/inc/experimental/generator @@ -55,11 +55,13 @@ namespace experimental { return {}; } -#ifdef _CPPUNWIND void unhandled_exception() noexcept { +#ifdef _CPPUNWIND _Eptr = _STD current_exception(); - } +#else // ^^^ _CPPUNWIND / !_CPPUNWIND vvv + abort(); #endif // _CPPUNWIND + } void _Rethrow_if_exception() { #ifdef _CPPUNWIND From f4be83e505f76e84cebc1e558baa7e77a8909528 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Fri, 21 Aug 2020 09:20:50 -0700 Subject: [PATCH 2/3] VSO-967814 has been fixed ... but VSO-1172852 remains, so we must keep the `exception_ptr` and rethrowing machinery in place for now. Let's annotate all of this workaround machinery properly, and demonstrate how to elide it after the bug is fixed. Also avoid defining `unhandled_exception` in legacy coroutine mode when `_CPPUNWIND` isn't defined; legacy coroutines deal with this case in a different way that we don't want to regress. --- stl/inc/experimental/generator | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/stl/inc/experimental/generator b/stl/inc/experimental/generator index 9ad1cb20937..fd8eb755bbb 100644 --- a/stl/inc/experimental/generator +++ b/stl/inc/experimental/generator @@ -38,10 +38,11 @@ namespace experimental { struct generator { struct promise_type { _Ty const* _CurrentValue; +#if 1 // TRANSITION, VSO-1172852 #ifdef _CPPUNWIND - // TRANSITION, VSO-967814 exception_ptr _Eptr; #endif // _CPPUNWIND +#endif // TRANSITION, VSO-1172852 auto get_return_object() { return generator{*this}; @@ -55,14 +56,21 @@ namespace experimental { return {}; } +#if defined(_CPPUNWIND) || defined(__cpp_impl_coroutine) void unhandled_exception() noexcept { +#if 1 // TRANSITION, VSO-1172852 #ifdef _CPPUNWIND _Eptr = _STD current_exception(); #else // ^^^ _CPPUNWIND / !_CPPUNWIND vvv abort(); #endif // _CPPUNWIND +#else // ^^^ workaround / no workaround + throw; +#endif // TRANSITION, VSO-1172852 } +#endif // defined(_CPPUNWIND) || defined(__cpp_impl_coroutine) +#if 1 // TRANSITION, VSO-1172852 void _Rethrow_if_exception() { #ifdef _CPPUNWIND if (_Eptr) { @@ -70,6 +78,7 @@ namespace experimental { } #endif // _CPPUNWIND } +#endif // TRANSITION, VSO-1172852 auto yield_value(_Ty const& _Value) { _CurrentValue = _STD addressof(_Value); @@ -119,7 +128,11 @@ namespace experimental { iterator& operator++() { _Coro.resume(); if (_Coro.done()) { +#if 1 // TRANSITION, VSO-1172852 _STD exchange(_Coro, {}).promise()._Rethrow_if_exception(); +#else // ^^^ workaround / no workaround + _Coro = nullptr; +#endif // TRANSITION, VSO-1172852 } return *this; @@ -152,7 +165,9 @@ namespace experimental { if (_Coro) { _Coro.resume(); if (_Coro.done()) { +#if 1 // TRANSITION, VSO-1172852 _Coro.promise()._Rethrow_if_exception(); +#endif // TRANSITION, VSO-1172852 return {nullptr}; } } @@ -166,10 +181,8 @@ namespace experimental { explicit generator(promise_type& _Prom) : _Coro(coroutine_handle::from_promise(_Prom)) {} - generator() = default; - + generator() = default; generator(generator const&) = delete; - generator& operator=(generator const&) = delete; generator(generator&& _Right) : _Coro(_Right._Coro) { From 268f3f83506b2827478d7b4cf047ef07e15d3ea3 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Mon, 24 Aug 2020 14:27:08 -0700 Subject: [PATCH 3/3] Apply suggestions from code review Fixup #else comments. --- stl/inc/experimental/generator | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stl/inc/experimental/generator b/stl/inc/experimental/generator index fd8eb755bbb..60e2a896de7 100644 --- a/stl/inc/experimental/generator +++ b/stl/inc/experimental/generator @@ -64,7 +64,7 @@ namespace experimental { #else // ^^^ _CPPUNWIND / !_CPPUNWIND vvv abort(); #endif // _CPPUNWIND -#else // ^^^ workaround / no workaround +#else // ^^^ workaround / no workaround vvv throw; #endif // TRANSITION, VSO-1172852 } @@ -130,7 +130,7 @@ namespace experimental { if (_Coro.done()) { #if 1 // TRANSITION, VSO-1172852 _STD exchange(_Coro, {}).promise()._Rethrow_if_exception(); -#else // ^^^ workaround / no workaround +#else // ^^^ workaround / no workaround vvv _Coro = nullptr; #endif // TRANSITION, VSO-1172852 }