[Issue 15703] New: @safe code should not allow certain types of array casts

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Feb 18 11:36:43 PST 2016


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

          Issue ID: 15703
           Summary: @safe code should not allow certain types of array
                    casts
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: hsteoh at quickfur.ath.cx

Currently, this code compiles:

-------
void main() @safe
{
     Object[] objs = [ new Object() ];
     long[] longs = cast(long[]) objs;
     longs[0] = 12345; // corrupts the Object reference
}
-------

It should be illegal to cast an array of types with indirections in @safe code.
Except perhaps to an array of const, e.g., const(long)[] (reading the
indirections should be no problem, but writing to it via an array cast will
break @safe).

--


More information about the Digitalmars-d-bugs mailing list