diff --git a/CMakeLists.txt b/CMakeLists.txt index e25f7fae..aa082676 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,13 +120,6 @@ else() cxx_feature_check(THREAD_SAFETY_ATTRIBUTES) endif() - # GCC doesn't report invalid -Wno-warning flags, so check the positive - # version, and if it exists add the negative. - check_cxx_warning_flag(-Winvalid-offsetof) - if (HAVE_CXX_FLAG_WINVALID_OFFSETOF) - add_cxx_compiler_flag(-Wno-invalid-offsetof) - endif() - # On most UNIX like platforms g++ and clang++ define _GNU_SOURCE as a # predefined macro, which turns on all of the wonderful libc extensions. # However g++ doesn't do this in Cygwin so we have to define it ourselfs diff --git a/src/benchmark.cc b/src/benchmark.cc index 5082716b..356ed548 100644 --- a/src/benchmark.cc +++ b/src/benchmark.cc @@ -311,10 +311,23 @@ State::State(size_t max_iters, const std::vector& ranges, int thread_i, CHECK(max_iterations != 0) << "At least one iteration must be run"; CHECK_LT(thread_index, threads) << "thread_index must be less than threads"; + // Note: The use of offsetof below is technically undefined until C++17 + // because State is not a standard layout type. However, all compilers + // currently provide well-defined behavior as an extension (which is + // demonstrated since constexpr evaluation must diagnose all undefined + // behavior). However, GCC and Clang also warn about this use of offsetof, + // which must be suppressed. +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Winvalid-offsetof" +#endif // Offset tests to ensure commonly accessed data is on the first cache line. const int cache_line_size = 64; static_assert(offsetof(State, error_occurred_) <= (cache_line_size - sizeof(error_occurred_)), ""); +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif } void State::PauseTiming() {