Bug 20345 – writing through `void[]` cannot be @safe

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-11-01T10:57:19Z
Last change time
2024-10-04T12:51:39Z
Keywords
safe
Assigned to
No Owner
Creator
ag0aep6g

Comments

Comment #0 by ag0aep6g — 2019-11-01T10:57:19Z
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. */ } ----
Comment #1 by dkorpel — 2024-10-04T12:51:39Z
Fixed by https://github.com/dlang/dmd/pull/16584 *** This issue has been marked as a duplicate of issue 24603 ***