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.