From d76681ce53439d497bab278342a1d5659edec608 Mon Sep 17 00:00:00 2001 From: Oliver Beckstein Date: Fri, 3 Apr 2026 16:20:36 -0700 Subject: [PATCH] work around clang warn/error on __COUNTER__ - fix #186 - code generated by Cursor and reviewed by @orbeckst - note: vendored googlebench contains __COUNTER__ that is classified by clang as a C2y extension and -Werror and -pedantic-errors makes this fail (even though it is actually supported). This is fixed (worked around) in upstream googlebench but other things changed there and would possibly require some rewriting here. Instead, we opted to just remove -Werror -pedantic-error around the googlebench code. --- libdistopia/CMakeLists.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libdistopia/CMakeLists.txt b/libdistopia/CMakeLists.txt index a715bdd..0ed3164 100644 --- a/libdistopia/CMakeLists.txt +++ b/libdistopia/CMakeLists.txt @@ -34,13 +34,23 @@ endif() if(DISTOPIA_BUILD_TESTS) set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Enable googlebench tests" FORCE) + # Newer Clang warns on __COUNTER__ in #if (C2y extension); googlebench uses -Werror. + set(BENCHMARK_ENABLE_WERROR OFF CACHE BOOL "Build googlebench without -Werror" FORCE) add_subdirectory("googlebench") + # Clang 17+ warns on __COUNTER__ in #if (C2y); -pedantic-errors still makes it fatal for googlebench. + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + target_compile_options(benchmark PRIVATE -Wno-c2y-extensions) + target_compile_options(benchmark_main PRIVATE -Wno-c2y-extensions) + endif() add_executable(bench) target_sources(bench PRIVATE "test/bench.cpp") target_link_libraries(bench PUBLIC benchmark::benchmark) target_link_libraries(bench PUBLIC libdistopia) target_include_directories(bench PUBLIC ${CMAKE_CURRENT_LIST_DIR}) + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + target_compile_options(bench PRIVATE -Wno-c2y-extensions) + endif()