AA invalidating pointers and references..?

simendsjo simen.endsjo at pandavre.com
Sun Aug 8 08:02:27 PDT 2010


unittest
{
	auto a = [1:2];
	auto p = 1 in a;
	// can p be invalidated by rehashing?
	// That is pointing to a different item or a memory location used for 
other things?

	auto b = a.rehash;
	
	// The spec also says it orders in place, but returns the reorganized 
array...
	// Is the spec right? That it rehashes in place and returns a reference to
	// itself?
	assert(a is b);
}

unittest
{
	auto a = [1:2];
	auto p = 1 in a;
	a.remove(1);
	// the memory for p can be reassigned by the gc,
	// so this is undefined behavior.. right?
	assert(*p == 2);
}


More information about the Digitalmars-d-learn mailing list