This should not work, since alternative ways of doing so (including manual creation of delegate object and initialization of .ptr and .funcptr properties is rejected) are banned.
import std.stdio;
struct S
{
int i;
void bar()
{
++i;
}
void foo() immutable
{
//bar(); //error
(&bar)(); //works, lang hole
}
}
void main()
{
immutable S s;
writeln(s.i);
s.foo();
writeln(s.i);
}
dmd is smart enough to avoid delegate allocation, it just issues call directly to bar()
Comment #1 by maxim — 2013-02-06T12:55:41Z
Forgot to mention:
void delegate() dg = &bar;
dg();
also is accepted.
Comment #2 by k.hara.pg — 2015-02-24T03:03:57Z
*** This issue has been marked as a duplicate of issue 1983 ***