[Issue 24552] New: cast to immutable in @safe not rejected
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu May 16 02:24:23 UTC 2024
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 at puremagic.com
Reporter: elpenguino+D at 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.
--
More information about the Digitalmars-d-bugs
mailing list