No. Using the general purpose allocator after deinit is undefined behavior. It does not check whether it is initialized or not, so it can’t return an error. You’re supposed to just not do this.
In the deinit method, you’ll see that it sets itself to undefined, to help catch bugs like these. When you use it, it’s trying to use a very high index (0xAAAA…), hence the trap.
I understand it shouldn’t be done like this. It does not help to catch bugs, since you cannot debug something, when there is no trace or at least some error message on one architecture and it hangs forever on another. My question is why it relies on undefined behaviour when it is clearly an error? And why on x86_64 I can see at least some output, when on some other archs cannot? What if I simply forget to add defer?
It trapped. You can inspect the data at that point and you’ll se a bunch of 0xAA, the hallmark of using an initialized value.
The variation between platforms is what happens when you have undefined behavior.
Even if all else fails, at the very least you know that that specific piece of code is to blame. And it consistently fails, even if the method of failure varied amongst platforms. If the allocator didn’t set itself as undefined, you’d get silently working code, that sometimes breaks, classic Heisenbug, the worst thing that can happen in a program.
It’s clearly an error for you, human, not for a program. How can the allocator know if the index it’s trying to use is an unitialized value or a legitimate index? If the allocator kept track of it’s state for you, you’d have to pay for this, in the form of, i.e., a boolean, that it checks before every operation. It doesn’t make sense to pay this cost. We could add this boolen only in debug builds, and then assert if it has the correct value at every function call, but the result would be the same, you’d get a trap somewhere because the assertion failed, not returning an error. The best we could do is display a nice error message if the boolean is not holding the value we expected. It’s probably not worth the effort. Just set it to undefined, the user will figure it out when they see a bunch of 0xAA.