Created attachment 1021
Test case.
DMD2 cannot cast away the immutable modifier a variable, or raise a suitable
error for it.
Attached code outputs:
0
0
0
2
Where the following is expected:
0
2
0
2
... or some kind of error.
Comment #1 by dlang-bugzilla — 2011-09-05T07:11:12Z
Casting is the tool which allows you to break D's typesystem. This behavior is completely expected and is by design. If you use a cast, it's expected that you know what you're doing.
Note that your code will not compile with @safe:
test.d(5): Error: cast from const(int*) to int* not allowed in safe code