aboutsummaryrefslogtreecommitdiff
path: root/src/bench/bench.h
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2017-02-07 19:07:29 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2017-02-07 19:07:29 +0100
commit29c53289a9e6bb34a098ea87d923968e3ac6d75d (patch)
tree5f9a42f47526e1daa742ac1adeb6617eef37740f /src/bench/bench.h
parentb709fe7ffc44ae14bbd2403cdfbfa4fcf94cef6b (diff)
bench: Fix initialization order in registration
The initialization order of global data structures in different implementation units is undefined. Making use of this is essentially gambling on what the linker does, the so-called [Static initialization order fiasco](https://isocpp.org/wiki/faq/ctors#static-init-order). In this case it apparently worked on Linux but failed on OpenBSD and FreeBSD. To create it on first use, make the registration structure local to a function. Fixes #8910.
Diffstat (limited to 'src/bench/bench.h')
-rw-r--r--src/bench/bench.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/bench/bench.h b/src/bench/bench.h
index 80dad6a8ef..0e7605c726 100644
--- a/src/bench/bench.h
+++ b/src/bench/bench.h
@@ -63,7 +63,8 @@ namespace benchmark {
class BenchRunner
{
- static std::map<std::string, BenchFunction> benchmarks;
+ typedef std::map<std::string, BenchFunction> BenchmarkMap;
+ static BenchmarkMap &benchmarks();
public:
BenchRunner(std::string name, BenchFunction func);