From b40db869451036d222d155bc8cd6420c2fb9527a Mon Sep 17 00:00:00 2001 From: Afanasyev Ivan Date: Wed, 1 Nov 2023 17:09:15 +0700 Subject: [PATCH] Fix unit tests compilation with non-gnu / non-msvc compilers with c++11 support. (#1691) donotoptimize_test.cc could not be compiled under non-gnu / non-msvc compilers, because only deprecated version of DoNotOptimize is available for these compilers. Tests are compiled with -Werror. Patch fixes test compilation by providing non-deprecated version of DoNotOptimize for compilers with c++11 standard support. Co-authored-by: dominic <510002+dmah42@users.noreply.github.com> --- include/benchmark/benchmark.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/benchmark/benchmark.h b/include/benchmark/benchmark.h index 23103571..adf219a5 100644 --- a/include/benchmark/benchmark.h +++ b/include/benchmark/benchmark.h @@ -584,6 +584,12 @@ inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const& value) { inline BENCHMARK_ALWAYS_INLINE void ClobberMemory() { _ReadWriteBarrier(); } #endif #else +#ifdef BENCHMARK_HAS_CXX11 +template +inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp&& value) { + internal::UseCharPointer(&reinterpret_cast(value)); +} +#else template BENCHMARK_DEPRECATED_MSG( "The const-ref version of this method can permit " @@ -591,6 +597,12 @@ BENCHMARK_DEPRECATED_MSG( inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const& value) { internal::UseCharPointer(&reinterpret_cast(value)); } + +template +inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp& value) { + internal::UseCharPointer(&reinterpret_cast(value)); +} +#endif // FIXME Add ClobberMemory() for non-gnu and non-msvc compilers, before C++11. #endif