C++ Logo

std-proposals

Advanced search

[std-proposals] Coroutine<T> func () noexcept - Bad Alloc

From: Ryan P. Nicholl <rnicholl_at_[hidden]>
Date: Fri, 02 Jan 2026 23:10:13 +0000
Currently, if a coroutine function is declared noexcept, this triggers std::terminate on alloc fail.

I would like to suggest that if frame construction fails due to memory, the compiler attempts to construct a value of Ret using an instance of std::bad_alloc{} before throwing std::bad_alloc (and calling std::terminate if marked noexcept)

For example:

class coroutine_type
{
struct promise_type { ... }
private:
coroutine_type (promise_type *) { ... }
public:
coroutine_type(std::bad_alloc) {
// Handle here
}
};

This would allow declaring noexcept coroutine functions like:

coroutine_type myfunc(...) noexcept;

--
Ryan P. Nicholl
Tel: (678)-358-7765

Received on 2026-01-02 23:10:18