[Issue 19380] New: Access through nested struct's .init does not segfault

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Nov 9 04:12:34 UTC 2018


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

          Issue ID: 19380
           Summary: Access through nested struct's .init does not segfault
           Product: D
           Version: D2
          Hardware: All
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: stanislav.blinov at gmail.com

Perhaps not the title you'd expect on an issue tracker, but hopefully the code
makes it clear:

```
void main() {
    int x;
    struct S {
        void foo() {
            x++; // nested, accessing main's frame
        }
    }
    assert(S.init.tupleof[$-1] is null);
    // if the above assertion passes, how come this doesn't segfault?..
    S.init.foo(); // A

    import std.stdio;
    writeln("You shouldn't be here... ", x);

    // compared to:
    S s = S.init;
    assert(s.tupleof[$-1] is null);
    s.foo(); // B
}
```

It does (correctly?) segfault on A when compiled with LDC, but only on B with
DMD.

--


More information about the Digitalmars-d-bugs mailing list