www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18567] New: immutability hole related to context pointers

https://issues.dlang.org/show_bug.cgi?id=18567

          Issue ID: 18567
           Summary: immutability hole related to context pointers accessed
                    through const pure methods
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: critical
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: timon.gehr gmx.ch

DMD 2.079.0

void main(){
    int i = 0;
    struct S{
        const(int)* fun()const pure{
            return &i;
        }
    }
    immutable S s;
    static const(int)* foo(immutable(S) s)pure{
            return s.fun();
    }
    immutable(int) *pi=foo(s);
    import std.stdio;
    writeln(*pi); // 0
    i+=1;
    writeln(*pi); // 1
}

I.e. the data *pi is typed as immutable(int), yet changes.

--
Mar 06 2018