From 3ed68109bd4a266848e89fbf6d9f51be4976d9a0 Mon Sep 17 00:00:00 2001 From: Omair Javaid Date: Fri, 4 Oct 2024 18:04:34 +0500 Subject: [PATCH] Fix MicroBenchmark build on Linux with clang 18.1.8 (#141) MicroBenchmarks/libs/benchmark/test/options_test.cc fails to build on Linux/AArch64 with following error: error: variable 'actual_iterations' set but not used This patch adds benchmark::DoNotOptimize(actual_iterations); to to function BM_explicit_iteration_count in options_test.cc -Wall and -Werror were being used to compile and I am surprised that this was not caught by any of the buildbots. Some versions of clang compile this all fine with -Wall -Werror. --- MicroBenchmarks/libs/benchmark/test/options_test.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MicroBenchmarks/libs/benchmark/test/options_test.cc b/MicroBenchmarks/libs/benchmark/test/options_test.cc index d424d40b9..663fd1dc3 100644 --- a/MicroBenchmarks/libs/benchmark/test/options_test.cc +++ b/MicroBenchmarks/libs/benchmark/test/options_test.cc @@ -67,6 +67,8 @@ void BM_explicit_iteration_count(benchmark::State& state) { assert(state.max_iterations == 42); size_t actual_iterations = 0; for (auto _ : state) ++actual_iterations; + benchmark::DoNotOptimize(actual_iterations); + assert(actual_iterations == 42); assert(state.iterations() == state.max_iterations); assert(state.iterations() == 42); }