Bug in destructors

Rob Grainger rob_grainger2000 at yahoo.co.uk
Mon Sep 13 11:19:15 PDT 2010


The following example is based on one from The D Programming Language. I'd expect the last assertion in
the unittest to succeed, it fails.

class Buffer {
	private void* data;

	// Constructor
	this () {
		data = malloc(1024);
	}
	// Destructor
	~this() {
		free(data);
		data = null;
	}
}
unittest {
	auto b = new Buffer;
	auto b1 = b;
	clear(b);				// Get rid of b's extra state
	assert (b1.data is null);	// Should be ok, fails
}


More information about the Digitalmars-d mailing list