Why will the delete keyword be removed?

Jonathan M Davis jmdavisprog at gmail.com
Wed Jul 14 18:00:49 PDT 2010


On Wednesday, July 14, 2010 17:42:21 Vladimir Panteleev wrote:
> By "reaching that state" I meant a state as would be visible by code other
> than the object constructor or destructor. As Michel said, Andrei's
> proposal leaves the object in a state where its invariants could fail.

Ah, okay. That state could indeed be invalid from the perspective of the code 
logic. It is, however, defined. So, it's a lot like floats being NAN after an 
error. It shouldn't happen, but if it does, the result is well-defined. The main 
issue, however, is how this state is seen. It's not flagged in any way, so it's 
not necessarily clear when an error occurs that it's due to the object having 
been cleared rather than it being a valid object in an unexpected state. At 
least with NAN, it's pretty clear that you have an error due to an operation 
resulting in a NAN, and you can track it down. With things being put in the pre-
constructor state by clear(), it's not as obvious what's going on when things go 
wrong. Ideally, you'd want things to blow up when such an object was used, with 
it clearly indicating that it was because you used an object which isn't 
supposed to exist anymore.

So, clear() does result in a nice, defined state - which is far better than 
undefined behavior - but it's not a state where tracking down the error is 
necessarily going to be at all obvious or simple. So, it's a step in the right 
direction, but I'm not sure that it's enough.

- Jonathan M Davis


More information about the Digitalmars-d mailing list