[Issue 18587] Context pointer not set for delegate template parameter when declared in struct body

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Mar 12 07:07:34 UTC 2018


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |WONTFIX

--- Comment #1 from Simen Kjaeraas <simen.kjaras at gmail.com> ---
Since structs in D are movable by simple blitting with no cleanup step, this is
impossible. If we consider this code again:

struct S {
    int n;
    R!(() => n) a;
}

struct R(alias fn) {
    int get() {
        return fn();
    }
}

The layout of R would essentially be this:

struct R(alias fn) {
    S* context;
}

Thus, the layout of S would essentially be this:

struct S {
    int n;
    S* a.context;
}

That's an internal pointer, and runs afoul of this section of the GC spec[0]:

> Do not have pointers in a struct instance that point back to the same instance. The trouble with this is if the instance gets moved in memory, the pointer will point back to where it came from, with likely disastrous results.

[0]: https://dlang.org/spec/garbage.html

--


More information about the Digitalmars-d-bugs mailing list