Date: Sat, 3 Jan 2026 14:10:35 +1030
There is already a mechanism you can use to return a different value in the
case of a failure to allocate storage for a coroutine frame.
If your coroutine's promise_type provides a static function named get_
return_object_on_allocation_failure then, in the case that allocating a
coroutine frame fails, the invocation of the coroutine will return
promise_type::get_return_object_on_allocation_failure().
See [dcl.fct.def.coroutine] p11
<https://eel.is/c++draft/dcl.fct.def.coroutine#11>.
Cheers,
Lewis.
On Sat, 3 Jan 2026 at 09:40, Ryan P. Nicholl via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> 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
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
case of a failure to allocate storage for a coroutine frame.
If your coroutine's promise_type provides a static function named get_
return_object_on_allocation_failure then, in the case that allocating a
coroutine frame fails, the invocation of the coroutine will return
promise_type::get_return_object_on_allocation_failure().
See [dcl.fct.def.coroutine] p11
<https://eel.is/c++draft/dcl.fct.def.coroutine#11>.
Cheers,
Lewis.
On Sat, 3 Jan 2026 at 09:40, Ryan P. Nicholl via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> 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
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
Received on 2026-01-03 03:40:51
