Bug 15762 – Array casts involving const enums can be made @safe

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-03-05T00:35:00Z
Last change time
2017-07-02T17:05:11Z
Keywords
pull, safe
Assigned to
nobody
Creator
dhasenan
See also
https://issues.dlang.org/show_bug.cgi?id=12068

Comments

Comment #0 by dhasenan — 2016-03-05T00:35:13Z
According to dmd 2.070.0: enum Windows1252Char : ubyte { init } void main() @safe { ubyte[] a = [1, 2, 3, 4]; auto aw = cast(Windows1252Char[]) a; // valid auto caw = cast(const(Windows1252Char)[]) a; // valid const(ubyte)[] c = [1, 2, 3, 4]; auto d = cast(const(Windows1252Char)[]) c; // invalid } arrcast.d(9): Error: cast from const(ubyte)[] to const(Windows1252Char)[] not allowed in safe code The compiler is fine if I cast mutable to mutable, or mutable to const, but I can't cast const to const. Why not? Switching from an enum type to a builtin type or struct makes things work, so this looks like an oversight. Context: I'm trying to make a @safe version of std.encoding, which does a ton of casting between array types. I have to make much more code @trusted than I'd like, and allowing const(ubyte) -> const(enum) casts would lead to far less @trusted code.
Comment #1 by bugzilla — 2016-06-20T10:45:49Z
Comment #2 by github-bugzilla — 2016-06-26T12:31:03Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/932be192e3b5039778daf03ea77253a8806f676a fix Issue 15762 - Array casts involving const enums can be made @safe https://github.com/dlang/dmd/commit/a56ce297d1cfd2ef295a80abc8106c5be5f9fd19 Merge pull request #5878 from WalterBright/fix15762 fix Issue 15762 - Array casts involving const enums can be made @safe
Comment #3 by github-bugzilla — 2016-10-01T11:47:57Z
Commits pushed to stable at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/932be192e3b5039778daf03ea77253a8806f676a fix Issue 15762 - Array casts involving const enums can be made @safe https://github.com/dlang/dmd/commit/a56ce297d1cfd2ef295a80abc8106c5be5f9fd19 Merge pull request #5878 from WalterBright/fix15762