https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120243
Bug ID: 120243
Summary: [15/16 Regression] Exception rethrown from coroutine
promise type unhandled_exception not caught under -O1
Product: gcc
Version: 15.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: rs2740 at gmail dot com
Target Milestone: ---
#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");
}
}
This prints "Caught!" with -O0 but terminates with
> terminate called after throwing an instance of 'char const*'
with -O1 or higher.