non-instance accessibility of immutable instance variables with initializers

Timon Gehr timon.gehr at gmx.ch
Sun Jun 3 06:40:32 PDT 2012


DMD 2.059:

struct S{
     immutable x = [1];
     immutable y = 1;
}

void main(){
     writeln(S.x);        // ok
     writeln(&S.x);       // ok
     writeln(S.y);        // ok
     // writeln(&S.y);    // error
     with(S) writeln(&y); // ok (but resulting pointer is wrong)
}

This behaviour is obviously buggy, but I am not sure to what extent.

What is the intended behaviour? Should initialised immutable instance
variables be accessible without an instance at all?


More information about the Digitalmars-d mailing list