Skip to content

Commit

Permalink
Merge pull request #6404 from wilzbach/fix-18704
Browse files Browse the repository at this point in the history
Fix Issue 18704 - std/datetime/stopwatch.d(452) assertion failure on auto-tester
merged-on-behalf-of: Sebastian Wilzbach <sebi.wilzbach@gmail.com>
  • Loading branch information
dlang-bot committed Apr 5, 2018
2 parents 193c61d + 6f1bb46 commit 74e6dab
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion std/datetime/stopwatch.d
Expand Up @@ -445,7 +445,14 @@ Duration[fun.length] benchmark(fun...)(uint n)

int a;
void f0() nothrow {}
void f1() nothrow { auto b = to!string(a); }
void f1() nothrow @trusted {
// do not allow any optimizer to optimize this function away
import core.thread : getpid;
import core.stdc.stdio : printf;
auto b = getpid.to!string;
if (getpid == 1) // never happens, but prevents optimization
printf("%p", &b);
}
auto r = benchmark!(f0, f1)(1000);
assert(r[0] >= Duration.zero);
assert(r[1] > Duration.zero);
Expand Down

0 comments on commit 74e6dab

Please sign in to comment.