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

          Issue ID: 20230
           Summary: segfault in dmd due to inconsistent conversion of
                    function closure to delegate at compile time
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: [email protected]
          Reporter: [email protected]

---
struct A {
    int delegate(int) f;
    int delegate(int) g;
}

A s;
A r = {
    f: delegate (int v) { return 41 + v; },
    g: (int v) { return 665 + v; }
};
A u = {
    f: delegate (int v) { return 41 + v; },
    g: delegate (int v) { return 665 + v; }
};

void
main()
{
    import std.stdio;

    s.f = delegate (int v) { return 41 + v; };
    s.g = (int v) { return 665 + v; };

    s.f(1).writeln;
    s.g(1).writeln;
    u.f(1).writeln;
    u.g(1).writeln;
    r.f(1).writeln;
    r.g(1).writeln; /* segfault on dmd */
}
---

I stumbled upon this issue through pure accident where I meant to be using
function instead of delegate in a structure field, and I only noticed the
problem when I compiled with dmd once in a blue moon, rather than ldc2 which
doesn't exhibit the segfault.

--

Reply via email to