Bug 15466 – Incorrect result for 'real'

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2015-12-22T00:43:23Z
Last change time
2022-10-24T15:47:34Z
Assigned to
No Owner
Creator
Ali Cehreli

Comments

Comment #0 by acehreli — 2015-12-22T00:43:23Z
I was able to reduce the code to the following, which involves std.datetime.benchmark. However, I have not investigated whether this is a compiler or Phobos bug. Hence the vague subject. :( The bug manifests itself only if the four conditions are satisfied in the reduced code (-O, -inline, etc. do not make any difference): import std.stdio; import std.datetime; alias T = real; // Must be 'real' enum testCount = 7; // Must be > 6 T foo() { // Must return a value return 42; } void main() { // Must cast to void const m = benchmark!(() => cast(void)foo)(testCount); writeln(m[0].msecs); } The output of the program (test measurement) is not 0 (or a very small number of milliseconds) as one would expect: -9223372036854775808 Ali
Comment #1 by razvan.nitu1305 — 2022-10-24T13:45:31Z
Hi, Ali! I was not able to compile your initial code in the bug report, so I slightly modified it to compile: ```d import std.stdio; import std.datetime.stopwatch; // this was `import std.datetime;` alias T = real; // Must be 'real' enum testCount = 7; // Must be > 6 T foo() { // Must return a value return 42; } void main() { // Must cast to void const m = benchmark!(() => cast(void)foo)(testCount); writeln(m[0].total!"msecs"); // this was `writeln(m[0].msecs);` } ``` Running this code yields `0`. I will close this as WORKSFORME, but please reopen if there is anything that I am missing.
Comment #2 by acehreli — 2022-10-24T15:47:34Z
Thanks! Works for me as well.