C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Save Cascading Free of Smart Pointers

From: Thiago Macieira <thiago_at_[hidden]>
Date: Tue, 16 Jul 2024 16:45:24 -0700
On Tuesday 16 July 2024 14:13:20 GMT-7 M.C.A. (Marco) Devillers via Std-
Proposals wrote:
> This cascading free behaviour was noticed during the development of
> the Egel language interpreter, and the author has great interest in
> having this resolved. The problem was discussed on various channels
> and together with Alipha on libera.net a solution was developed. The
> idea was subsequently floated on the GCC mailing list where it was
> forwarded.

In addition to what others have said, this allocates memory during the
destruction phase, so your safe_unique_ptr destructor is noexcept(false).
That's a big design problem: we try to have them be free of exceptions.
Because what happens if you run out of memory while trying to free memory?

What happens if you're trying to free memory *because* you're about to run out
of memory? Instead of freeing memory, you'd end up causing the very thing
you're trying to prevent.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel DCAI Platform & System Engineering

Received on 2024-07-16 23:45:29