May 16 [Issue 24552] New: cast to immutable in @safe not rejected | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=24552 Issue ID: 24552 Summary: cast to immutable in @safe not rejected Product: D Version: D2 Hardware: All OS: All Status: NEW Keywords: accepts-invalid Severity: critical Priority: P1 Component: dmd Assignee: nobody@puremagic.com Reporter: elpenguino+D@gmail.com ``` 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. -- |
Copyright © 1999-2021 by the D Language Foundation