Commit bd8108c1 authored by Orvid King's avatar Orvid King Committed by facebook-github-bot-4

Implement a generalized mechanism for pushing/popping warnings

Summary: Folly synchronized requires disabling the shadow warning in a macro, but that doesn't work under MSVC, so abstract a mechansim out that allows them to be handled gracefully.

Reviewed By: yfeldblum

Differential Revision: D2870357

Pulled By: Orvid

fb-gh-sync-id: a4b0e425736ddd5293f020b360244554571d397f
parent 23e1c2d3
...@@ -161,6 +161,31 @@ ...@@ -161,6 +161,31 @@
# define FOLLY_PACK_POP /**/ # define FOLLY_PACK_POP /**/
#endif #endif
// Generalize warning push/pop.
#if defined(_MSC_VER)
# define FOLLY_PUSH_WARNING __pragma(warning(push))
# define FOLLY_POP_WARNING __pragma(warning(pop))
// Disable the GCC warnings.
# define FOLLY_GCC_DISABLE_WARNING(warningName)
# define FOLLY_MSVC_DISABLE_WARNING(warningNumber) __pragma(warning(disable: warningNumber))
#elif defined(__clang__) || defined(__GNUC__)
# define FOLLY_PUSH_WARNING _Pragma("GCC diagnostic push")
# define FOLLY_POP_WARNING _Pragma("GCC diagnostic pop")
#define FOLLY_GCC_DISABLE_WARNING_INTERNAL3(warningName) #warningName
#define FOLLY_GCC_DISABLE_WARNING_INTERNAL2(warningName) \
FOLLY_GCC_DISABLE_WARNING_INTERNAL3(warningName)
#define FOLLY_GCC_DISABLE_WARNING(warningName) \
_Pragma(FOLLY_GCC_DISABLE_WARNING_INTERNAL2(GCC diagnostic ignored \
FOLLY_GCC_DISABLE_WARNING_INTERNAL3(-W##warningName)))
// Disable the MSVC warnings.
# define FOLLY_MSVC_DISABLE_WARNING(warningNumber)
#else
# define FOLLY_PUSH_WARNING
# define FOLLY_POP_WARNING
# define FOLLY_GCC_DISABLE_WARNING(warningName)
# define FOLLY_MSVC_DISABLE_WARNING(warningNumber)
#endif
// portable version check // portable version check
#ifndef __GNUC_PREREQ #ifndef __GNUC_PREREQ
# if defined __GNUC__ && defined __GNUC_MINOR__ # if defined __GNUC__ && defined __GNUC_MINOR__
......
...@@ -682,8 +682,8 @@ void swap(Synchronized<T, M>& lhs, Synchronized<T, M>& rhs) { ...@@ -682,8 +682,8 @@ void swap(Synchronized<T, M>& lhs, Synchronized<T, M>& rhs) {
* examples. * examples.
*/ */
#define SYNCHRONIZED(...) \ #define SYNCHRONIZED(...) \
_Pragma("GCC diagnostic push") \ FOLLY_PUSH_WARNING \
_Pragma("GCC diagnostic ignored \"-Wshadow\"") \ FOLLY_GCC_DISABLE_WARNING(shadow) \
if (bool SYNCHRONIZED_state = false) {} else \ if (bool SYNCHRONIZED_state = false) {} else \
for (auto SYNCHRONIZED_lockedPtr = \ for (auto SYNCHRONIZED_lockedPtr = \
(FB_ARG_2_OR_1(__VA_ARGS__)).operator->(); \ (FB_ARG_2_OR_1(__VA_ARGS__)).operator->(); \
...@@ -691,7 +691,7 @@ void swap(Synchronized<T, M>& lhs, Synchronized<T, M>& rhs) { ...@@ -691,7 +691,7 @@ void swap(Synchronized<T, M>& lhs, Synchronized<T, M>& rhs) {
for (auto& FB_ARG_1(__VA_ARGS__) = \ for (auto& FB_ARG_1(__VA_ARGS__) = \
*SYNCHRONIZED_lockedPtr.operator->(); \ *SYNCHRONIZED_lockedPtr.operator->(); \
!SYNCHRONIZED_state; SYNCHRONIZED_state = true) \ !SYNCHRONIZED_state; SYNCHRONIZED_state = true) \
_Pragma("GCC diagnostic pop") FOLLY_POP_WARNING
#define TIMED_SYNCHRONIZED(timeout, ...) \ #define TIMED_SYNCHRONIZED(timeout, ...) \
if (bool SYNCHRONIZED_state = false) {} else \ if (bool SYNCHRONIZED_state = false) {} else \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment