Comment #0 by qs.il.paperinik — 2020-12-21T23:32:38Z
The offending code is below (you should be able to comment-in @nogc using -dip1000).
On my Windows machine, the listing compiles and runs seemingly without errors. Note that all attributes including @safe are circumvented. For @nogc, use -dip1000.
On run.dlang.org, running all DMD compilers, only 2.066 correctly points out attribute violation. Since 2.067 the compiler is beigng "killed by signal 11" (whatever that means). LDC segfaults.
int functional(int delegate(int) @system dg) @system
{
int* p;
int x;
p = &x;
if (auto result = dg(1)) return result;
return 0;
}
int functional(int delegate(int) @safe pure nothrow @nogc dg) @safe pure nothrow /*@nogc*/
{
return functional(dg);
}
void main() @safe pure nothrow /*@nogc*/
{
int x = 0;
functional(i => x = i);
assert(x == 1);
}
Comment #1 by moonlightsentinel — 2021-01-02T01:27:45Z
Attributes for function literals are inferred nowadays and `i => x = i` is inferred as @safe pure nothrow @nogc, hence calling the second overload of functional. That causes an infinite recursion and crashes due to a stack overflow.