← Back to index
|
Original Bugzilla link
Bug 24552 – cast to immutable in @safe not rejected
Status
NEW
Severity
critical
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-05-16T02:24:23Z
Last change time
2024-12-13T19:35:15Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
elpenguino+D
Moved to GitHub: dmd#18240 →
Comments
Comment #0
by elpenguino+D — 2024-05-16T02:24:23Z
``` void fun() @safe { static struct Foo(E) { private E[] data; Foo!NewElement opCast(T : Foo!NewElement, NewElement)() { return Foo!NewElement(cast(NewElement[])data); } } int[] data = [1,2,3,4,5]; Foo!int tmp = Foo!int(data); immutable tmp2 = (cast(immutable Foo!uint)tmp).data; assert(tmp2[2] == 3); data[2] = 77; assert(tmp2[2] == 77); // immutable data mutated?! } ``` This should not be allowed to compile.
Comment #1
by nick — 2024-05-16T12:47:07Z
As is(immutable Foo!uint : Foo!uint) is false, `opCast` should not be matched.
Comment #2
by robert.schadek — 2024-12-13T19:35:15Z
THIS ISSUE HAS BEEN MOVED TO GITHUB
https://github.com/dlang/dmd/issues/18240
DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB