[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 17:20:08 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=22563
--- Comment #2 from Stanislav Blinov <stanislav.blinov at gmail.com> ---
It should in @safe code, which is where `scope` matters. The only way to escape
it should be to break @safe. Isn't that the whole point?..
void* global;
struct Escapist(T)
{
T value;
}
@safe
void consumeThingWithContext(S)(scope S s)
if (is(S == struct) && __traits(isNested, S))
{
import core.lifetime;
global = s.tupleof[$-1]; // error: scope variable `s` assigned to
non-scope `global`
global = move(s.tupleof[$-1]); // error: scope variable `s` assigned to
non-scope `global`
auto escape = new Escapist!S(s); // with dip1000: scope variable `s` may
not be copied into allocated memory
}
@safe /*@nogc*/
void main()
{
int a;
struct Nested { ~this() @nogc { a++; } }
consumeThingWithContext(Nested());
}
--
More information about the Digitalmars-d-bugs
mailing list