Safe cast away from immutable

Iakh via Digitalmars-d digitalmars-d at puremagic.com
Mon Feb 8 11:07:01 PST 2016


import std.stdio;

struct S
{
     void[] arr;

     auto f() pure @safe
     {
         int[] a = new int[4];
         arr = a;
         return a;
     }
}
void main() @safe
{
     S s;
     immutable a = s.f();
     int[] b = (cast(int[])s.arr);
     writeln(a);
     b[0] = 1;
     writeln(a);
}

http://dpaste.dzfl.pl/13751913d2ff


More information about the Digitalmars-d mailing list