RFC: Change what assert does on error

Sebastiaan Koppe mail at skoppe.eu
Sat Jul 5 07:59:21 UTC 2025


On Saturday, 5 July 2025 at 06:57:21 UTC, Jonathan M Davis wrote:
> On Friday, July 4, 2025 5:09:27 PM Mountain Daylight Time Timon 
> Gehr via Digitalmars-d wrote:
>> A destructor can do anything, not just call `free`. Not 
>> calling them is way more likely to leave behind an unexpected 
>> state than even the original error condition. The state can be 
>> perfectly fine, it's just that the code that attempted to 
>> operate on it may be buggy.
>
> [...]
>
> 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.
>
> - Jonathan M Davis

Absolutely. In today's distributed world that hourglass could 
also be something remote and leading to downstream issues.

For example, it is not uncommon for key-value stores to support a 
lock operation. You will want it to try unlocking during shutdown.


More information about the Digitalmars-d mailing list