[Issue 21565] @safe code allows modification of a scalar that overlaps with a pointer

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jan 20 23:48:32 UTC 2021


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

--- Comment #3 from Steven Schveighoffer <schveiguy at gmail.com> ---
A union between a pointer and integer is most definitely unsafe in all
instances. If you never intend to access the int*, in any circumstance, then
why have a union?

If you do intend to access the int *, then having any safe code anywhere just
change the integer ruins the any safety assumptions that the @trusted or
@system code can make. Essentially, it means @trusted code can never access
such a union reliably except to access just the integer.

This means that T is OK to use ONLY in @system code, or ONLY in @safe code, but
NEVER in @trusted code (unless you just follow the @safe rules).

I don't feel like we should bend the spec over backwards to fit with the
implementation, when there isn't really a benefit (other than being able to
close a bug report).

--


More information about the Digitalmars-d-bugs mailing list