[Issue 1312] New: invariant storage class within a struct/class

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jul 3 18:50:44 PDT 2007


http://d.puremagic.com/issues/show_bug.cgi?id=1312

           Summary: invariant storage class within a struct/class
           Product: D
           Version: 2.002
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: Daniel919 at web.de


There is an unwanted behaviour when using an invariant storage class within a
struct/class.

------------------------------------------------------------------------
import std.stdio;

struct MyStruct
{
    int x = 1;
    invariant int y = 2;

    //void resety() { y = 3; }; //error: constant y is not an lvalue - as
expected

    /*
        alternatives, that work as expected:
        const int y = 2;
        static invariant int y = 2;

        final int y = 2; //but this takes up storage for each instance
    */
}

void main() {
        MyStruct mystruct;
        mystruct.x = 1; //ok
        //mystruct.y == 1, expected: 2
        //mystruct.y = 2; //no error, but mystruct.x also becomes 2
        writefln("mystruct.sizeof: %s mystruct.x: %s mystruct.y: %s",
mystruct.sizeof, mystruct.x, mystruct.y);
}


-- 



More information about the Digitalmars-d-bugs mailing list