[Issue 3622] New: Nested structs as default function arguments not initialized

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Dec 16 13:44:36 PST 2009


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

           Summary: Nested structs as default function arguments not
                    initialized
           Product: D
           Version: 2.036
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: tomeksowi at gmail.com


--- Comment #0 from Tomasz Sowiński <tomeksowi at gmail.com> 2009-12-16 13:44:35 PST ---
Strangely enough it happens only if the nested struct is forward referenced.
Looks like the default argument is not initialized at all in these cases.

Testcase (should pass):

struct Strukt {
    int pole;
    Wsk wsk;

    this(int pole, Wsk wsk = Wsk()) {
        this.pole = pole;
        this.wsk = wsk;
    }

    static Wsk zla_funkcja(uint i, Wsk wsk = Wsk()) {
        return wsk;
    }

    struct Wsk {
        Strukt* w;
    }

    static Wsk funkcja(uint i, Wsk wsk = Wsk()) {
        return wsk;
    }
}


void main() {
    auto ok = Strukt.funkcja(7);
    assert(!ok.w);  // passes

    auto zly = Strukt.zla_funkcja(7);
    assert(!zly.w);     // boom!

    auto s = Strukt(6);
    assert (!s.wsk.w);  // boom!
}

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


More information about the Digitalmars-d-bugs mailing list