benchmark icon indicating copy to clipboard operation
benchmark copied to clipboard

[BUG] Passing -pedantic -Werror but relying on extensions

Open AaronBallman opened this issue 2 months ago • 1 comments

The build script passes -pedantic -Werror: https://github.com/google/benchmark/blob/4e26a9e6eedb3e89c448cf7115352cb085fdb713/CMakeLists.txt#L207

However, the code relies on extensions: https://github.com/google/benchmark/blob/4e26a9e6eedb3e89c448cf7115352cb085fdb713/include/benchmark/benchmark.h#L1484

While working on implementing __COUNTER__ for C2y mode in Clang (https://github.com/llvm/llvm-project/pull/162662), I've added the expected extension and pre-compat warnings, which then cause the code in benchmark.h to fail to compile because of -pedantic-errors.

There's a few ways to solve this, but I'm not familiar enough with benchmark to know which is the best way to go. You could stop using __COUNTER__ entirely and just use the __LINE__ fallback since that has to work to be a useful fallback anyway. You could stop passing -pedantic and continuing using __COUNTER__. You could use __extension__ to silence the extension warning. Other ideas likely exist.

AaronBallman avatar Oct 15 '25 17:10 AaronBallman

I think this particular warning would just need to be silenced in this paricular case. Loosening requested warning flags runs the risk of allowing other extensions slipping in (well, not really, but better to just not go there i'd say.)

LebedevRI avatar Oct 15 '25 17:10 LebedevRI

Thanks for pointing out, the benchmark library is not compilable with the latest emscripten compiler (which, may jave updated the clang upstream code).

In file included from build-wasm/_deps/benchmark-src/src/benchmark_register.cc:39:
build-wasm/_deps/benchmark-src/include/benchmark/benchmark.h:1461:30: error: '__COUNTER__' is a C2y extension [-Werror,-Wc2y-extensions]
 1461 | #if defined(__COUNTER__) && (__COUNTER__ + 1 == __COUNTER__ + 0)

Hope this be fixed.

LanderlYoung avatar Dec 16 '25 06:12 LanderlYoung

Hi @LebedevRI, I’d love to take this on! If it's open for external contributors.

Could you please share a bit more information on the expected behavior? Any pointers or context would be really helpful before I get started. Thanks!

KaranPradhan266 avatar Dec 16 '25 17:12 KaranPradhan266