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

          Issue ID: 20345
           Summary: writing through `void[]` cannot be @safe
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: safe
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: [email protected]
          Reporter: [email protected]

Came up in the discussion of an "@system variables" DIP:
https://github.com/dlang/DIPs/pull/179#discussion_r341512564

A `void[]` might alias pointers so writing through it cannot be allowed in
`@safe` code.

----
void main() @safe
{
    int*[] p = [new int];
    void[] v = p;
    size_t[] x = [0xDEADBEEF];
    v[] = x[]; /* Creates an invalid `int*`. Should be rejected. */
    import std.stdio;
    writeln(p[0]); /* Prints "DEADBEEF", i.e. `p[0]` is an invalid pointer. */
}
----

--

Reply via email to