From abafced9909c7e5e8f6b8236eecd953caa4f8e6f Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Sun, 30 Jul 2017 18:41:57 -0600 Subject: [PATCH] Suppress -Wodr on C++03 tests when LTO is enabled. The benchmark library is compiled as C++11, but certain tests are compiled as C++03. When -flto is enabled GCC 5.4 and above will diagnose an ODR violation in libstdc++'s . This ODR violation, although real, should likely be benign. For this reason it seems sensible to simply suppress -Wodr when building the C++03 test. This patch fixes #420 and supersede's PR #424. --- test/CMakeLists.txt | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b55612b4..02d58616 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -106,13 +106,20 @@ add_test(user_counters_tabular_test user_counters_tabular_test --benchmark_count check_cxx_compiler_flag(-std=c++03 BENCHMARK_HAS_CXX03_FLAG) if (BENCHMARK_HAS_CXX03_FLAG) - set(CXX03_FLAGS "${CMAKE_CXX_FLAGS}") - string(REPLACE "-std=c++11" "-std=c++03" CXX03_FLAGS "${CXX03_FLAGS}") - string(REPLACE "-std=c++0x" "-std=c++03" CXX03_FLAGS "${CXX03_FLAGS}") - compile_benchmark_test(cxx03_test) set_target_properties(cxx03_test - PROPERTIES COMPILE_FLAGS "${CXX03_FLAGS}") + PROPERTIES + COMPILE_FLAGS "-std=c++03") + # libstdc++ provides different definitions within between dialects. When + # LTO is enabled and -Werror is specified GCC diagnoses this ODR violation + # causing the test to fail to compile. To prevent this we explicitly disable + # the warning. + check_cxx_compiler_flag(-Wno-odr BENCHMARK_HAS_WNO_ODR) + if (BENCHMARK_ENABLE_LTO AND BENCHMARK_HAS_WNO_ODR) + set_target_properties(cxx03_test + PROPERTIES + LINK_FLAGS "-Wno-odr") + endif() add_test(cxx03 cxx03_test --benchmark_min_time=0.01) endif()