[Issue 15542] pure function with no argument returning different values (with void-initialized static array)
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Nov 23 16:23:56 UTC 2017
https://issues.dlang.org/show_bug.cgi?id=15542
Jonathan M Davis <issues.dlang at jmdavisProg.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |issues.dlang at jmdavisProg.co
| |m
--- Comment #3 from Jonathan M Davis <issues.dlang at jmdavisProg.com> ---
I would argue that this simply isn't a bug. void initializers are an @system
way to allow you to delay initialization so that you don't default-initialize a
variable and then assign to it again shortly thereafter. You're never supposed
to actually use the value of a void initialized variable any more than it's
advised to use a variable in C/C++ that you didn't initialize and thus is
filled with garbage. The fact that the pure function returns different values
for different calls is simply a result of failing to do your due diligence with
an @system function and make sure that it's actually @safe in spite of the
@system operations that it's doing. You'd have the same problem if you made it
do pointer arithmetic that made it point past the end of a buffer. There are
plenty of other ways to end up pointing to varying things whenever you violate
@safe. There's nothing particularly special about the void initializer in that
regard. You'd basically have to force all pure functions to be @safe if you
wanted to avoid this problem.
--
More information about the Digitalmars-d-bugs
mailing list