google / benchmark

A microbenchmark support library
Apache License 2.0
8.69k stars 1.59k forks source link

[BUG] cxx03_test Fails Due to C++ Version #1597

Closed joshdorsey closed 10 months ago

joshdorsey commented 1 year ago

Describe the bug A clean build of the google benchmark library as described here fails with an error after the last command: "C++11 or greater detected. Should be C++03."

System Which OS, compiler, and compiler version are you using:

To reproduce Steps to reproduce the behavior:

  1. Checkout the repo to 318dd44
  2. cmake -E make_directory "build"
  3. cmake -E chdir "build" cmake -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on -GNinja -DCMAKE_BUILD_TYPE=Release ../
  4. cmake --build "build" --config Release
  5. Uh-oh!
    FAILED: test/CMakeFiles/cxx03_test.dir/cxx03_test.cc.obj
    C:\PROGRA~1\LLVM\bin\CLANG_~1.EXE -DBENCHMARK_STATIC_DEFINE -DHAVE_STD_REGEX -DHAVE_STEADY_CLOCK -DHAVE_THREAD_SAFETY_ATTRIBUTES -DTEST_BENCHMARK_LIBRARY_HAS_NO_ASSERTIONS -I../include -Wall  -Wextra  -Wshadow  -Wfloat-equal  -Werror  -pedantic  -pedantic-errors  -Wshorten-64-to-32  -fstrict-aliasing  -Wno-deprecated-declarations  -Wno-deprecated  -Wstrict-aliasing  -Wthread-safety -O3  -D_DLL -D_MT -Xclang --dependent-lib=msvcrt -fvisibility-inlines-hidden   -UNDEBUG -w -std=c++14 -MD -MT test/CMakeFiles/cxx03_test.dir/cxx03_test.cc.obj -MF test\CMakeFiles\cxx03_test.dir\cxx03_test.cc.obj.d -o test/CMakeFiles/cxx03_test.dir/cxx03_test.cc.obj -c ../test/cxx03_test.cc
    ../test/cxx03_test.cc:8:2: error: C++11 or greater detected. Should be C++03.
    #error C++11 or greater detected. Should be C++03.
    ^
    ../test/cxx03_test.cc:12:2: error: C++11 or greater detected by the library. BENCHMARK_HAS_CXX11 is defined.
    #error C++11 or greater detected by the library. BENCHMARK_HAS_CXX11 is defined.
    ^
    2 errors generated.

Expected behavior The library to build successfully and to be able to link against it.

Additional context I noticed there were some other (closed) tickets with the same issue that didn't have satisfying resolutions for my situation, but they seemed to be using more unconventional compilers than me. The Google benchmark library I do have compiled from a couple years ago (835951a) complains about being built in debug mode when you run it, surely this would happen to anyone building the benchmark library how it's intended to be built and then linking their debug-mode code against it? Maybe that's a bad idea to begin with on my part, not sure. I also noticed that -std=c++14 ends up in the command line that causes the error, I assume that's the cause but I didn't do anything to make it do that, this is just in its own folder.

Thanks 😄

dmah42 commented 1 year ago

we should be skipping that test (fairly obviously given the name) when we're building for greater than c++03. https://github.com/google/benchmark/blob/main/test/CMakeLists.txt#L181 is the relevant bit of the build config.

clang on windows may be the "unusual" bit here. perhaps we need to extend that conditional?