Skip to content

Commit

Permalink
fix Issue 13871 - Segmentation fault from std/variant.d:609
Browse files Browse the repository at this point in the history
A variant to variant assignment is specially handled by OpID.copyOut. Therefore, destroying original value before the copyOut call is problematic.
  • Loading branch information
9rnsr committed Dec 31, 2014
1 parent 356c5e9 commit 2e69efe
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions std/variant.d
Expand Up @@ -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))
{
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 2e69efe

Please sign in to comment.