google / benchmark

A microbenchmark support library
Apache License 2.0
8.59k stars 1.57k forks source link

`Wconversion` compile warnings since `1.8.4` #1789

Closed romintomasetti closed 1 month ago

romintomasetti commented 1 month ago

We are including Benchmark within our project using the CMake FetchContent approach.

This means that Benchmark gets compiled with the some compiler (and global compile options) as the rest of the project.

Since today's release of Benchmark 1.8.4, we are seeing several -Wconversion issues:

/opt/google-benchmark-1.8.4/src/benchmark_runner.cc:374:39: error: conversion from 'long int' to 'double' may change value [-Werror=conversion]
  374 |   return std::sqrt(i.seconds_pow2 / i.iters -

I think that it could be fixed with static_cast. For now, our fix is to add:

target_compile_options(benchmark PRIVATE -Wno-error=conversion)
LebedevRI commented 1 month ago

I don't see that line where the your snippet says it is: https://github.com/google/benchmark/blob/v1.8.4/src/benchmark_runner.cc#L374 In fact, there's no seconds_pow2 in the entire codebase:

$ git grep seconds_pow2
$
romintomasetti commented 1 month ago

@LebedevRI Sorry for the noise, I was using the patch from https://github.com/google/benchmark/pull/1744/files...