On Wednesday, 6 February 2013 at 18:15:53 UTC, Dan wrote:
This workaround succeeds, but, based on this thread
(http://forum.dlang.org/thread/[email protected])
I don't know if it is a bug or not. If it is not a bug, I would
doubt it is the prescribed approach for doing this?
Thanks,
Dan
Huh, ability to call non-const postblit from const __postblit is
actually a general problem of a major type system breakage:
import std.stdio;
struct S
{
int i;
void bar()
{
++i;
}
void foo() immutable
{
//#1
//bar(); //error
//(&bar)(); //works, lang hole
//#2
void delegate() dg1 = &bar; //works, lang hole
//dg1(); //
//#3
void delegate() dg2;
//dg.ptr = this; //error
dg2.ptr = cast(void*)&this;
//dg.funcptr = &S.bar; //error
dg2.funcptr = cast(void function())&S.bar;
dg2(); //works due to cast
}
}
void main()
{
immutable S s;
writeln(s.i);
s.foo();
writeln(s.i);
}
The fact that bar() does not work and (&bar)() works is terrific.
Also, if dg1 call is uncommented, dmd wrongly generates
instruction which leads to segfault.