[Issue 15704] New: @safe code should not allow copying of void[]

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Feb 18 15:05:34 PST 2016


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

          Issue ID: 15704
           Summary: @safe code should not allow copying of void[]
           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

-----
void main() @safe {
    Object[] objs = [ new Object() ];
    void[] arr1 = objs;
    void[] arr2 = [ 123, 345, 567 ];

    arr1[] = arr2[];  // overwrites pointers with arbitrary ints
}
-----

It should be illegal to copy the contents of one void[] to another void[],
since void[] by definition is a type-erased array and can represent any
arbitrary type, including types with indirections. Since type information has
been erased, there is no way to verify that the destination array has no
indirections, so to guarantee @safety, such an operation must not be allowed in
@safe code.

--


More information about the Digitalmars-d-bugs mailing list