[Issue 14585] New: destructor called on garbage in std.variant

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri May 15 04:41:34 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=14585

          Issue ID: 14585
           Summary: destructor called on garbage in std.variant
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: Phobos
          Assignee: nobody at puremagic.com
          Reporter: ag0aep6g at gmail.com

Originally found by Fyodor Ustinov who posted to digitalmars.D.learn and
digitalmars.D:
http://forum.dlang.org/post/nobzbhpqsbzutljejifj@forum.dlang.org
http://forum.dlang.org/post/oqjnjvchzatzkaboeygz@forum.dlang.org

Pull request on the way.

----
import std.stdio;
import std.variant: Variant;

struct S
{
    int x = 42;
    ~this()
    {
        writeln("x: ", x);
        assert(x == 42);
    }
}

void main()
{
    Variant(S()).get!S;
}
----

Output (truncated):
----
x: 42
x: 42
x: 42
x: 7017840
x: 42
core.exception.AssertError at test4.d(10): Assertion failure
----

--


More information about the Digitalmars-d-bugs mailing list