[Issue 24162] Another example of why @safe is broken

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Sep 27 08:52:32 UTC 2023


https://issues.dlang.org/show_bug.cgi?id=24162

--- Comment #7 from anonymous4 <dfj1esp02 at sneakemail.com> ---
(In reply to tomerfiliba from comment #2)
> accessing this memory location no longer does what it was meant to do.

If this function doesn't reflect your intention, then write a function that
reflects your intention, like:

@safe:
import std.stdio: writeln;

void f(int x, ref int[] arr) {
    arr[x] += 1;
    arr ~= new int[900000];
    arr[x] += 1;
}

void main() {
    auto arr = new int[10];
    f(2, arr);
    writeln(arr[0..10]);
}

--


More information about the Digitalmars-d-bugs mailing list