Fix for issue 4942

This commit is contained in:
Andrei Alexandrescu 2011-01-22 19:17:40 +00:00
parent 4196a49db4
commit 3d865b35b6
2 changed files with 42 additions and 2 deletions

View file

@ -2003,7 +2003,7 @@ Complexity: $(BIGOH log(n)).
static if (is(T == struct))
{
// Destroy this guy
clear(_data._payload[$ - 1]);
.clear(_data._payload[$ - 1]);
}
_data._payload = _data._payload[0 .. $ - 1];
}
@ -2031,7 +2031,7 @@ Complexity: $(BIGOH howMany).
// Destroy this guy
foreach (ref e; _data._payload[$ - howMany .. $])
{
clear(e);
.clear(e);
}
}
_data._payload = _data._payload[0 .. $ - howMany];
@ -4762,3 +4762,12 @@ unittest
RedBlackTree!ubyte rt5;
RedBlackTree!byte rt6;
}
version(unittest) struct UnittestMe {
int a;
}
unittest
{
auto c = Array!UnittestMe();
}

View file

@ -1451,6 +1451,37 @@ unittest
static assert(hasElaborateAssign!S3);
}
/**
True if $(D S) or any type directly embedded in the representation
of $(D S) defines an elaborate destructor. Elaborate destructors
are introduced by defining $(D ~this()) for a $(D
struct). (Non-struct types never have elaborate destructors, even
though classes may define $(D ~this()).)
*/
template hasElaborateDestructor(S)
{
static if(!is(S == struct))
{
enum bool hasElaborateDestructor = false;
}
else
{
enum hasElaborateDestructor = is(typeof({S s; return &s.__dtor;}))
|| anySatisfy!(.hasElaborateDestructor, typeof(S.tupleof));
}
}
unittest
{
static assert(!hasElaborateDestructor!int);
static struct S1 { }
static assert(!hasElaborateDestructor!S1);
static struct S2 { ~this() {} }
static assert(hasElaborateDestructor!S2);
static struct S3 { S2 field; }
static assert(hasElaborateDestructor!S3);
}
/**
Yields $(D true) if and only if $(D T) is a $(D struct) or a $(D
class) that defines a symbol called $(D name).