import std.stdio; struct S { int i; void bar() { ++i; } void foo() immutable { void delegate() dg1 = &bar; dg1(); // comment out to fix void delegate() dg2; dg2.ptr = cast(void*)&this; dg2.funcptr = cast(void function())&S.bar; dg2(); } } void main() { immutable S s; writeln(s.i); s.foo(); writeln(s.i); } Without dg1() call, dmd arranges registers's content correctly. However in presence of dg1 call it incorrectly rearranges them so that [rex.W callq] calls this pointer, not function pointer.
This appears to work correctly now.