From: Orvid King Date: Wed, 27 Jan 2016 21:57:12 +0000 (-0800) Subject: Implement a generalized mechanism for pushing/popping warnings X-Git-Tag: deprecate-dynamic-initializer~136 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=bd8108c1056e4bc84744e449456e97b8772d0f14;p=folly.git 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 --- diff --git a/folly/Portability.h b/folly/Portability.h index 8b95c31e..03717262 100644 --- a/folly/Portability.h +++ b/folly/Portability.h @@ -161,6 +161,31 @@ # define FOLLY_PACK_POP /**/ #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 #ifndef __GNUC_PREREQ # if defined __GNUC__ && defined __GNUC_MINOR__ diff --git a/folly/Synchronized.h b/folly/Synchronized.h index 668f6740..7c7e029c 100644 --- a/folly/Synchronized.h +++ b/folly/Synchronized.h @@ -682,8 +682,8 @@ void swap(Synchronized& lhs, Synchronized& rhs) { * examples. */ #define SYNCHRONIZED(...) \ - _Pragma("GCC diagnostic push") \ - _Pragma("GCC diagnostic ignored \"-Wshadow\"") \ + FOLLY_PUSH_WARNING \ + FOLLY_GCC_DISABLE_WARNING(shadow) \ if (bool SYNCHRONIZED_state = false) {} else \ for (auto SYNCHRONIZED_lockedPtr = \ (FB_ARG_2_OR_1(__VA_ARGS__)).operator->(); \ @@ -691,7 +691,7 @@ void swap(Synchronized& lhs, Synchronized& rhs) { for (auto& FB_ARG_1(__VA_ARGS__) = \ *SYNCHRONIZED_lockedPtr.operator->(); \ !SYNCHRONIZED_state; SYNCHRONIZED_state = true) \ - _Pragma("GCC diagnostic pop") + FOLLY_POP_WARNING #define TIMED_SYNCHRONIZED(timeout, ...) \ if (bool SYNCHRONIZED_state = false) {} else \