[Issue 22563] Nested structs, if not escaping, shouldn't allocate context (just like delegates)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Dec 3 20:23:28 UTC 2021


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

--- Comment #4 from kinke <kinke at gmx.net> ---
This currently compiles even with -dip1000:
```
void consumeThingWithContext(S)(scope S s)
if (is(S == struct) && __traits(isNested, S))
{
    static S global;
    global = s;
}

//@safe //@nogc
void main()
{
    int a;
    struct Nested { ~this() @safe @nogc { a++; } }
    consumeThingWithContext(Nested());
}
```

It's just not inferred to be @safe.

It segfaults at runtime, presumably because `global` is initialized statically
with null context pointer and cannot be successfully destructed prior to
reassignment...

--


More information about the Digitalmars-d-bugs mailing list