[Issue 24772] Casting class references to void* should be @safe
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Sep 20 13:53:40 UTC 2024
https://issues.dlang.org/show_bug.cgi?id=24772
Jonathan M Davis <issues.dlang at jmdavisProg.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |issues.dlang at jmdavisProg.co
| |m
--- Comment #8 from Jonathan M Davis <issues.dlang at jmdavisProg.com> ---
As a general rule, if we can guarantee that something is memory safe, it should
be @safe. The general issue is being absolutely certain that something cannot
result in memory corruption in @safe code. So, we do need to be careful in
verifying that.
However, if we are 100% sure that something will not result in violating memory
safety in purely @safe code, we arguably should enable it, and I'm not sure if
it really matters whether it clearly enables anything.
For this particular case, if the void* is immediately passed to something
@system, then the @safety doesn't really matter, because you'll need to slap
@trusted on it all anyway. However, if there is a use case where the class is
converted to void* in a separate piece of code, then it's arguably just
annoying to required @trusted in that part of the code.
But I've certainly run into the case where I have to slap @trusted on code or
use debug {} just because I'm trying to print out the pointer value of a class
reference.
--
More information about the Digitalmars-d-bugs
mailing list