From 29c53289a9e6bb34a098ea87d923968e3ac6d75d Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Tue, 7 Feb 2017 19:07:29 +0100 Subject: 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. --- src/bench/bench.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/bench/bench.h') 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 benchmarks; + typedef std::map BenchmarkMap; + static BenchmarkMap &benchmarks(); public: BenchRunner(std::string name, BenchFunction func); -- cgit v1.2.3