Bug 6604 – Casting away immutable modifier does nothing

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2011-09-05T06:52:00Z
Last change time
2011-09-05T07:11:12Z
Assigned to
nobody
Creator
rofflwaffls

Attachments

IDFilenameSummaryContent-TypeSize
1021test2.dTest case.application/octet-stream267

Comments

Comment #0 by rofflwaffls — 2011-09-05T06:52:33Z
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