From ff8d44c9282d23233ec8932585b0c3ae6557263f Mon Sep 17 00:00:00 2001 From: dominic <510002+dmah42@users.noreply.github.com> Date: Mon, 6 Feb 2023 17:34:47 +0100 Subject: [PATCH] fix #1446 by removing the address operator (#1538) * fix #1446 by removing the address operator * add test * format --------- Co-authored-by: Thomas Co-authored-by: Dominic Hamon --- include/benchmark/benchmark.h | 2 +- test/benchmark_test.cc | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/benchmark/benchmark.h b/include/benchmark/benchmark.h index b44cfc16..ba997e8c 100644 --- a/include/benchmark/benchmark.h +++ b/include/benchmark/benchmark.h @@ -1379,7 +1379,7 @@ class Fixture : public internal::Benchmark { BENCHMARK_PRIVATE_DECLARE(_benchmark_) = \ (::benchmark::internal::RegisterBenchmarkInternal( \ new ::benchmark::internal::FunctionBenchmark(#__VA_ARGS__, \ - &__VA_ARGS__))) + __VA_ARGS__))) #else #define BENCHMARK(n) \ BENCHMARK_PRIVATE_DECLARE(n) = \ diff --git a/test/benchmark_test.cc b/test/benchmark_test.cc index bd6005d1..ce233ece 100644 --- a/test/benchmark_test.cc +++ b/test/benchmark_test.cc @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -254,4 +255,16 @@ static void BM_BenchmarkName(benchmark::State& state) { } BENCHMARK(BM_BenchmarkName); +// regression test for #1446 +template +static void BM_templated_test(benchmark::State& state) { + for (auto _ : state) { + type created_string; + benchmark::DoNotOptimize(created_string); + } +} + +static auto BM_templated_test_double = BM_templated_test>; +BENCHMARK(BM_templated_test_double); + BENCHMARK_MAIN();