http://d.puremagic.com/issues/show_bug.cgi?id=6436

           Summary: Refcounted initialization bug
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nob...@puremagic.com
        ReportedBy: andrej.mitrov...@gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrov...@gmail.com> 2011-08-04 
13:35:13 PDT ---
import std.typecons;

struct Foo
{
    struct Payload
    {
        this(ref int bar, int value)
        { 
            bar = value;
            assert(bar == 5);   // ok
        }
    }

    alias RefCounted!(Payload, RefCountedAutoInitialize.yes) Data;
    Data data;

    int bar;

    this(int value) 
    {
        data = Data(bar, value);
        assert(bar == 5);  // throws, it's still 0
    }    
}

void main()
{
    auto foo = Foo(5);
}

import std.typecons;

struct Foo
{
    struct Payload
    {
        this(ref int bar, int value)
        { 
            bar = value;
            assert(bar == 5);   // ok..
        }
    }

    alias RefCounted!(Payload, RefCountedAutoInitialize.yes) Data;
    Data data;

    int bar;

    this(int value) 
    {
        data = Data(bar, value);  // initializes bar to 5
        assert(bar == 5);  // throws, it's still 0
    }    
}

void main()
{
    auto foo = Foo(5);
}

Foo's ctor is called, then Refcounted Payload's ctor is called which
initializes Foo's integer field, but upon return to the Foo ctor the integer
field seems to be reinitialized to 0.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to