syntax question on "invariant" keyword

Robert Fraser fraserofthenight at gmail.com
Tue Jul 3 18:31:47 PDT 2007


> struct S
> {
>     int x = 9;
>     invariant int y = 8;
>     void foo()
>     {
>         // y  = 7; // Expectedly, this fails to compile (GOOD).
>     }
> }
> void main() {
>     S a;
>     writefln("Size of S is %s", S.sizeof);
>     writefln("Before x=%s y=%s", a.x, a.y);
>     a.x = 1;
>     a.y = 2;
>     writefln("After  x=%s y=%s", a.x, a.y);
> }
> // ------------
> The results I get using DMD 2.002 are ...
> 
> c:\temp>test
> Size of S is 4
> Before x=9 y=9
> After  x=2 y=2
> 
> -- 
> Derek
> (skype: derek.j.parnell)
> Melbourne, Australia
> 4/07/2007 9:39:54 AM

Looks like a bug to me. A big one.


More information about the Digitalmars-d-learn mailing list