Skip to content

Commit

Permalink
Fix issue 10958 - Variant fails to compile for types with sizeof == 0.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kapps committed Feb 14, 2014
1 parent 3089fb2 commit b21c398
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion std/variant.d
Expand Up @@ -167,7 +167,6 @@ private:
ubyte[maxDataSize] data;
}
enum size = SizeChecker.sizeof - (int function()).sizeof;
static assert(size >= (void*).sizeof);

/** Tells whether a type $(D_PARAM T) is statically allowed for
* storage inside a $(D_PARAM VariantN) object by looking
Expand Down Expand Up @@ -1715,6 +1714,36 @@ unittest
assertThrown!VariantException(Variant(A(3)) < Variant(A(4)));
}

// Handling of empty types and arrays, e.g. issue 10958
unittest
{
class EmptyClass { }
struct EmptyStruct { }
alias EmptyArray = void[0];

alias Alg = Algebraic!(EmptyClass, EmptyStruct, EmptyArray);

Variant testEmpty(T)()
{
T inst;
Variant v = inst;
assert(v.get!T == inst);
assert(v.peek!T !is null);
assert(*v.peek!T == inst);
Alg alg = inst;
assert(alg.get!T == inst);
return v;
}

testEmpty!EmptyClass();
testEmpty!EmptyStruct();
testEmpty!EmptyArray();

EmptyArray e;
Variant v2 = e;
assert(v2.length == 0);
}

// Handling of void function pointers / delegates, e.g. issue 11360
unittest
{
Expand Down

0 comments on commit b21c398

Please sign in to comment.