Bug 15703 – @safe code should not allow certain types of array casts
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-02-18T19:36:00Z
Last change time
2016-10-01T11:48:34Z
Keywords
pull, safe
Assigned to
nobody
Creator
hsteoh
Comments
Comment #0 by hsteoh — 2016-02-18T19:36:43Z
Currently, this code compiles:
-------
void main() @safe
{
Object[] objs = [ new Object() ];
long[] longs = cast(long[]) objs;
longs[0] = 12345; // corrupts the Object reference
}
-------
It should be illegal to cast an array of types with indirections in @safe code. Except perhaps to an array of const, e.g., const(long)[] (reading the indirections should be no problem, but writing to it via an array cast will break @safe).