]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: add passing testcases [PR120243]
authorJason Merrill <jason@redhat.com>
Wed, 9 Jul 2025 15:13:19 +0000 (11:13 -0400)
committerJason Merrill <jason@redhat.com>
Wed, 9 Jul 2025 15:50:06 +0000 (11:50 -0400)
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.

gcc/testsuite/g++.dg/coroutines/torture/pr120243-unhandled-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/torture/pr120243-unhandled-2.C [new file with mode: 0644]

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 (file)
index 0000000..16bfef1
--- /dev/null
@@ -0,0 +1,33 @@
+// PR c++/120243
+// { dg-do run }
+
+#include <coroutine>
+
+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 (file)
index 0000000..614c4ec
--- /dev/null
@@ -0,0 +1,34 @@
+// PR c++/120243
+// { dg-do run }
+
+#include <coroutine>
+
+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<promise_type>::from_promise(*this)}; }
+        void return_void() {}
+    };
+
+    std::coroutine_handle<promise_type> h;
+};
+
+int main() {
+    auto c = []() -> coro {
+        throw "hello";
+        __builtin_abort();
+        co_return;
+    };
+    try {
+        c().h.resume();
+    }
+    catch(...) {
+        __builtin_printf("Caught!\n");
+    }
+}