[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 21:41:57 UTC 2017


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

--- Comment #5 from Jonathan M Davis <issues.dlang at jmdavisProg.com> ---
(In reply to ag0aep6g from comment #4)
> Note that the test code still compiles even when you add `@safe`. Void
> initialization of value types is considered `@safe`.

Hmmm. I'm inclined to think that that's a bug, but I suppose that it depends on
what types it lets you void initialize. I guess that if it's just ints and
floats and whatnot in the struct, then that doesn't actually pose a memory
safety problem and wouldn't need to be marked @system, but it still seems
wrong.

Either way, I think that it's pretty clear that you're dealing with undefined
behavior if you use a void-initialized object before giving it a proper value,
and I don't see any reason to treat pure as special in that regard. As long as
the variable is given a proper value, then there is no purity issue, and
regardless of  whether @safety concerns really apply in all cases with
void-inialization, the concept is basically the same. When the programmer
void-initializes something, they're essentially promising that they'll do the
right thing and give the variablie a value before using it so that the normal
guarantees are in place.

--


More information about the Digitalmars-d-bugs mailing list