Bug 14823 – pure function returns uninitialized value
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2015-07-24T15:11:57Z
Last change time
2023-06-28T14:34:27Z
Assigned to
No Owner
Creator
Jeff Thompson
Comments
Comment #0 by jeff — 2015-07-24T15:11:57Z
To reproduce, enter and run the following code:
import std.stdio;
pure int getUninitializedValue()
{
int[1] array = void; // array is uninitialized
return array[0];
}
void main(string[] args)
{
writeln(getUninitializedValue());
}
Expected result: Compiler error for a pure function with uninitialized memory.
Actual result: It prints 185734 (or another uninitialized value from the stack).
Suggested solution: Don't allow accessing uninitialized memory inside a pure function.
Comment #1 by razvan.nitu1305 — 2023-06-28T14:34:27Z
*** This issue has been marked as a duplicate of issue 15542 ***