[Issue 20969] alias to local in static instance of a struct causes segfault

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jun 22 12:17:35 UTC 2020


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

Simen Kjaeraas <simen.kjaras at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |simen.kjaras at gmail.com

--- Comment #2 from Simen Kjaeraas <simen.kjaras at gmail.com> ---
I'm not sure this is exactly the same issue, but it's certainly analogous:

unittest {
    import std.stdio;
    int i;
    writeln("Outside: ", &i);
    static fn = (){
        writeln("Inside: ", &i);
        ++i;
    };
    writeln("Context: ", fn.ptr);
    fn();
}


Output:
Outside: 3100014
Context: null
Inside: 4
(0): [unittest] Access Violation

As we can see, the context pointer for the delegate is not initialized.

Making it compile would either be equivalent to making 'i' static, or have
different behavior for the first and consequent calls, as only the first would
have its 'i' modified by calls to fn().

Sensible workarounds do exist, this is most likely to be a mistake by the
programmer, and having it work requires that this corner case be described
somewhere. I say make it an error.

--


More information about the Digitalmars-d-bugs mailing list