[Issue 20345] New: writing through `void[]` cannot be @safe
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Nov 1 10:57:19 UTC 2019
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 at puremagic.com
Reporter: ag0aep6g at 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. */
}
----
--
More information about the Digitalmars-d-bugs
mailing list