www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20345] New: writing through `void[]` cannot be safe

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: nobody puremagic.com
          Reporter: ag0aep6g gmail.com

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. */
}
----

--
Nov 01 2019