[Issue 24162] New: Another example of why @safe is broken
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Sep 26 06:36:37 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=24162
Issue ID: 24162
Summary: Another example of why @safe is broken
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: tomerfiliba at gmail.com
have a look at this snippet - all @safe, uses GC and no pointers:
https://run.dlang.io/is/KGbaEd
```
@safe:
import std.stdio: writeln;
void f(ref int x, ref int[] arr) {
x += 1; // this happens on arr[2]
arr ~= new int[900000]; // array is relocated
x += 1; // this now modifies random memory and will not be
reflected on arr
}
void main() {
auto arr = new int[10];
f(arr[2], arr);
writeln(arr[0..10]);
}
```
it passes two mutable references to the array, which means the array can be
relocated while a reference exists
--
More information about the Digitalmars-d-bugs
mailing list