Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
/ druntime Public archive
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/object.d
Original file line number Diff line number Diff line change
Expand Up @@ -2971,6 +2971,30 @@ unittest
assert(i == 0); // `i` is back to its initial state `0`
}

/********
To destroy a value type through a pointer, the pointer must be dereferenced.
Otherwise `destroy` will only destroy the pointer itself, not the entity being
referenced.
*/
nothrow @safe unittest
{
static struct S
{
static int dtorCount;
~this() { dtorCount++; }
}

S* s1 = new S();
destroy(s1); // destroys only the pointer `s1`, not what it references,
assert(s1 is null); // and sets the pointer to `null`
assert(S.dtorCount == 0);

S* s2 = new S();
destroy(*s2); // destroys the struct referenced by `s2`
assert(s2 !is null); // the pointer itself is not affected
assert(S.dtorCount == 1);
}

unittest
{
interface I { }
Expand Down