From 2c84854b90f626032c47c88d1bbbc8af2b5bdab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Tue, 10 Aug 2021 00:33:56 +0200 Subject: [PATCH] Use unique_ptr to hold Environment measurements in benchmarking --- src/catch2/benchmark/detail/catch_estimate_clock.hpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/catch2/benchmark/detail/catch_estimate_clock.hpp b/src/catch2/benchmark/detail/catch_estimate_clock.hpp index 984acd11..3bba791e 100644 --- a/src/catch2/benchmark/detail/catch_estimate_clock.hpp +++ b/src/catch2/benchmark/detail/catch_estimate_clock.hpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -94,7 +95,14 @@ namespace Catch { template Environment> measure_environment() { - static Environment>* env = nullptr; +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wexit-time-destructors" +#endif + static Catch::Detail::unique_ptr>> env; +#if defined(__clang__) +# pragma clang diagnostic pop +#endif if (env) { return *env; } @@ -103,7 +111,7 @@ namespace Catch { auto resolution = Detail::estimate_clock_resolution(iters); auto cost = Detail::estimate_clock_cost(resolution.mean); - env = new Environment>{ resolution, cost }; + env = Catch::Detail::make_unique>>( Environment>{resolution, cost} ); return *env; } } // namespace Detail