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).
Comment #1 by bugzilla — 2016-08-26T05:44:14Z
Comment #2 by github-bugzilla — 2016-08-26T21:13:22Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/2dcdc9563c286de39bf4eba3083bef77c49f7a5e fix Issue 15703 - @safe code should not allow certain types of array casts https://github.com/dlang/dmd/commit/e9594ecaaa3d231aa13e2df21be7b72bdf0e4ae6 Merge pull request #6086 from WalterBright/fix15703 fix Issue 15703 - @safe code should not allow certain types of array …
Comment #3 by github-bugzilla — 2016-10-01T11:48:34Z
Commits pushed to stable at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/2dcdc9563c286de39bf4eba3083bef77c49f7a5e fix Issue 15703 - @safe code should not allow certain types of array casts https://github.com/dlang/dmd/commit/e9594ecaaa3d231aa13e2df21be7b72bdf0e4ae6 Merge pull request #6086 from WalterBright/fix15703