From: Jason Merrill Date: Wed, 9 Jul 2025 15:13:19 +0000 (-0400) Subject: c++: add passing testcases [PR120243] X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2492bab503f57f2cf6e08e5c104f7a1d31d34047;p=thirdparty%2Fgcc.git c++: add passing testcases [PR120243] These pass now; the first was fixed by r16-1507. PR c++/120243 gcc/testsuite/ChangeLog: * g++.dg/coroutines/torture/pr120243-unhandled-1.C: New test. * g++.dg/coroutines/torture/pr120243-unhandled-2.C: New test. --- diff --git a/gcc/testsuite/g++.dg/coroutines/torture/pr120243-unhandled-1.C b/gcc/testsuite/g++.dg/coroutines/torture/pr120243-unhandled-1.C new file mode 100644 index 00000000000..16bfef16fd8 --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/torture/pr120243-unhandled-1.C @@ -0,0 +1,33 @@ +// PR c++/120243 +// { dg-do run } + +#include + +struct coro { + struct promise_type { + promise_type() = default; + + std::suspend_never initial_suspend() const noexcept { return {}; } + std::suspend_never final_suspend() const noexcept { return {}; } + + void unhandled_exception() { throw; } + + coro get_return_object() { return {}; } + void return_void() {} + + }; +}; + +int main() { + auto c = []() -> coro { + throw "hello"; + __builtin_abort(); + co_return; + }; + try { + c(); + } + catch(...) { + __builtin_printf("Caught!\n"); + } +} diff --git a/gcc/testsuite/g++.dg/coroutines/torture/pr120243-unhandled-2.C b/gcc/testsuite/g++.dg/coroutines/torture/pr120243-unhandled-2.C new file mode 100644 index 00000000000..614c4ec9be6 --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/torture/pr120243-unhandled-2.C @@ -0,0 +1,34 @@ +// PR c++/120243 +// { dg-do run } + +#include + +struct coro { + struct promise_type { + promise_type() = default; + + std::suspend_always initial_suspend() const noexcept { return {}; } + std::suspend_always final_suspend() const noexcept { return {}; } + + void unhandled_exception() { throw; } + + coro get_return_object() { return {std::coroutine_handle::from_promise(*this)}; } + void return_void() {} + }; + + std::coroutine_handle h; +}; + +int main() { + auto c = []() -> coro { + throw "hello"; + __builtin_abort(); + co_return; + }; + try { + c().h.resume(); + } + catch(...) { + __builtin_printf("Caught!\n"); + } +}