fix(timing): Do not resume timing in pause scope on skipped benchmarks (#2318)
Currently, skipping a benchmark with an error from a `ScopedPauseTiming` fails
with GB built in debug mode, since `ResumeTiming()` is called outside of a benchmark
loop.
This mirrors the logic in `State::FinishKeepRunning()`, which pauses only if the
benchmark was not skipped. Leaving the timer paused is preferable to resuming after
a skip, which could then also corrupt timings.
diff --git a/include/benchmark/state.h b/include/benchmark/state.h
index 86009e2..69c4211 100644
--- a/include/benchmark/state.h
+++ b/include/benchmark/state.h
@@ -282,7 +282,9 @@
explicit ScopedPauseTiming(State& state) : state_(state) {
state_.PauseTiming();
}
- ~ScopedPauseTiming() { state_.ResumeTiming(); }
+ ~ScopedPauseTiming() {
+ if (!state_.skipped()) state_.ResumeTiming();
+ }
ScopedPauseTiming(const ScopedPauseTiming&) = delete;
void operator=(const ScopedPauseTiming&) = delete;