Skip to content

Commit 176ad6c

Browse files
Add deprecation warnings for MSVC (#1993)
* Add deprecation warnings for MSVC * Split `DoNotOptimize` overloads for MSVC
1 parent d24860f commit 176ad6c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

include/benchmark/benchmark.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,16 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
239239
_Pragma("diagnostic push") \
240240
_Pragma("diag_suppress deprecated_entity_with_custom_message")
241241
#define BENCHMARK_RESTORE_DEPRECATED_WARNING _Pragma("diagnostic pop")
242+
#elif defined(_MSC_VER)
243+
#define BENCHMARK_BUILTIN_EXPECT(x, y) x
244+
#define BENCHMARK_DEPRECATED_MSG(msg) __declspec(deprecated(msg))
245+
#define BENCHMARK_WARNING_MSG(msg) \
246+
__pragma(message(__FILE__ "(" BENCHMARK_INTERNAL_TOSTRING( \
247+
__LINE__) ") : warning note: " msg))
248+
#define BENCHMARK_DISABLE_DEPRECATED_WARNING \
249+
__pragma(warning(push)) \
250+
__pragma(warning(disable : 4996))
251+
#define BENCHMARK_RESTORE_DEPRECATED_WARNING __pragma(warning(pop))
242252
#else
243253
#define BENCHMARK_BUILTIN_EXPECT(x, y) x
244254
#define BENCHMARK_DEPRECATED_MSG(msg)
@@ -611,6 +621,17 @@ inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const& value) {
611621
_ReadWriteBarrier();
612622
}
613623

624+
template <class Tp>
625+
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp& value) {
626+
internal::UseCharPointer(&reinterpret_cast<char const volatile&>(value));
627+
_ReadWriteBarrier();
628+
}
629+
630+
template <class Tp>
631+
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp&& value) {
632+
internal::UseCharPointer(&reinterpret_cast<char const volatile&>(value));
633+
_ReadWriteBarrier();
634+
}
614635
#else
615636
template <class Tp>
616637
inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp&& value) {

0 commit comments

Comments
 (0)