fix Issue 13871 - Segmentation fault from std/variant.d:609

A variant to variant assignment is specially handled by OpID.copyOut. Therefore, destroying original value before the copyOut call is problematic.
This commit is contained in:
k-hara 2014-12-31 22:41:41 +09:00
parent 356c5e9a47
commit 2e69efed7e

View file

@ -605,8 +605,6 @@ public:
static assert(allowed!(T), "Cannot store a " ~ T.stringof
~ " in a " ~ VariantN.stringof ~ ". Valid types are "
~ AllowedTypes.stringof);
// Assignment should destruct previous value
fptr(OpID.destruct, &store, null);
static if (is(T : VariantN))
{
@ -620,6 +618,9 @@ public:
}
else
{
// Assignment should destruct previous value
fptr(OpID.destruct, &store, null);
static if (T.sizeof <= size)
{
// If T is a class we're only copying the reference, so it
@ -2514,6 +2515,17 @@ unittest
auto a = appender!(T[]);
}
unittest
{
// Bugzilla 13871
alias A = Algebraic!(int, typeof(null));
static struct B { A value; }
alias C = std.variant.Algebraic!B;
C var;
var = C(B());
}
unittest
{
// Make sure Variant can handle types with opDispatch but no length field.