RFC: Change what assert does on error

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sat Jul 5 07:07:00 UTC 2025


On Saturday, July 5, 2025 12:57:21 AM Mountain Daylight Time Jonathan M Davis via Digitalmars-d wrote:
> So, yeah, there's no reason to assume that destructors have anything to do
> with allocating or freeing anything. They're just functions that are
> supposed to be guaranteed to be run when a variable of that type is
> destroyed. They can be thought of as just being another form of scope(exit)
> except that they're tied to the type itself and so every object of that type
> gets that code instead of the programmer having to type it out wherever they
> want it.

Actually, to add to this, one case where skipping cleanup code could be
particularly catastrophic would be with mutexes. If a mutex is locked and
freed using RAII (or scope statements are used, and any of those are
skipped), then you could get into a situation where a lock is not released
like it was supposed to be, and then code higher up the stack which does run
while the stack is unwinding attempts to get that lock (and locks can be
used even if it's only for multi-threaded logging, and not all mutexes are
recursive), then the program could deadlock while the stack is unwinding
just because some of the cleanup code was skipped. So, skipping cleanup code
could actually result in the program failing to shutdown.

- Jonathan M Davis






More information about the Digitalmars-d mailing list