mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 06:30:28 +03:00
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:
parent
356c5e9a47
commit
2e69efed7e
1 changed files with 14 additions and 2 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue