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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Sep 26 12:40:46 UTC 2023


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

Dennis <dkorpel at live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |dkorpel at live.nl
         Resolution|---                         |INVALID

--- Comment #4 from Dennis <dkorpel at live.nl> ---
> but surely that's undefined behavior? 

It's not undefined behavior. The GC only frees memory with no references to it,
so keeping a reference to the old array keeps it alive.

> accessing this memory location no longer does what it was meant to do.

@safe is about preventing memory corruption, not bugs in general. The compiler
can't know what the intention of memory is, it just looks at size and lifetime.
Only if your reference becomes a dangling pointer or out of bounds in @safe
code, it's a bug.

--


More information about the Digitalmars-d-bugs mailing list