From e15da103f6c9008fd51886c033e1a732b4c1d750 Mon Sep 17 00:00:00 2001 From: Christopher Dykes Date: Sun, 9 Apr 2017 18:02:53 -0700 Subject: [PATCH] Refactor FOLLY_GCC_DISABLE_WARNING to play nice with clang-format Summary: Currently clang-format cannot be run on any file using the macro because it breaks it. By putting the warning name in a string clang-format no longer breaks it. Reviewed By: yfeldblum Differential Revision: D4856945 fbshipit-source-id: ebd2d223dd97f66224e9e2912610057e36287dae --- folly/Portability.h | 14 ++++++-------- folly/Synchronized.h | 2 +- folly/Traits.h | 4 ++-- folly/io/async/AsyncSocket.cpp | 6 +++--- folly/test/SingletonBenchmark.cpp | 2 +- folly/test/SingletonTest.cpp | 2 +- folly/test/SubprocessTest.cpp | 2 +- 7 files changed, 15 insertions(+), 17 deletions(-) diff --git a/folly/Portability.h b/folly/Portability.h index 77df9164..1792abf5 100644 --- a/folly/Portability.h +++ b/folly/Portability.h @@ -151,12 +151,10 @@ constexpr bool kIsSanitizeThread = false; #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))) +# define FOLLY_GCC_DISABLE_WARNING_INTERNAL2(warningName) #warningName +# define FOLLY_GCC_DISABLE_WARNING(warningName) \ + _Pragma( \ + FOLLY_GCC_DISABLE_WARNING_INTERNAL2(GCC diagnostic ignored warningName)) // Disable the MSVC warnings. # define FOLLY_MSVC_DISABLE_WARNING(warningNumber) #else @@ -168,8 +166,8 @@ constexpr bool kIsSanitizeThread = false; #ifdef HAVE_SHADOW_LOCAL_WARNINGS #define FOLLY_GCC_DISABLE_NEW_SHADOW_WARNINGS \ - FOLLY_GCC_DISABLE_WARNING(shadow-compatible-local) \ - FOLLY_GCC_DISABLE_WARNING(shadow-local) + FOLLY_GCC_DISABLE_WARNING("-Wshadow-compatible-local") \ + FOLLY_GCC_DISABLE_WARNING("-Wshadow-local") #else #define FOLLY_GCC_DISABLE_NEW_SHADOW_WARNINGS /* empty */ #endif diff --git a/folly/Synchronized.h b/folly/Synchronized.h index 5b6f9fc0..5d912034 100644 --- a/folly/Synchronized.h +++ b/folly/Synchronized.h @@ -1320,7 +1320,7 @@ void swap(Synchronized& lhs, Synchronized& rhs) { */ #define SYNCHRONIZED(...) \ FOLLY_PUSH_WARNING \ - FOLLY_GCC_DISABLE_WARNING(shadow) \ + FOLLY_GCC_DISABLE_WARNING("-Wshadow") \ FOLLY_MSVC_DISABLE_WARNING(4189) /* initialized but unreferenced */ \ FOLLY_MSVC_DISABLE_WARNING(4456) /* declaration hides local */ \ FOLLY_MSVC_DISABLE_WARNING(4457) /* declaration hides parameter */ \ diff --git a/folly/Traits.h b/folly/Traits.h index ec467180..4be2282c 100644 --- a/folly/Traits.h +++ b/folly/Traits.h @@ -546,9 +546,9 @@ struct is_negative_impl { // types) that violate -Wsign-compare and/or -Wbool-compare so suppress them // in order to not prevent all calling code from using it. FOLLY_PUSH_WARNING -FOLLY_GCC_DISABLE_WARNING(sign-compare) +FOLLY_GCC_DISABLE_WARNING("-Wsign-compare") #if __GNUC_PREREQ(5, 0) -FOLLY_GCC_DISABLE_WARNING(bool-compare) +FOLLY_GCC_DISABLE_WARNING("-Wbool-compare") #endif FOLLY_MSVC_DISABLE_WARNING(4388) // sign-compare FOLLY_MSVC_DISABLE_WARNING(4804) // bool-compare diff --git a/folly/io/async/AsyncSocket.cpp b/folly/io/async/AsyncSocket.cpp index ddbab294..013813f9 100644 --- a/folly/io/async/AsyncSocket.cpp +++ b/folly/io/async/AsyncSocket.cpp @@ -776,10 +776,10 @@ void AsyncSocket::writeChain(WriteCallback* callback, unique_ptr&& buf, size_t count = buf->countChainElements(); if (count <= kSmallSizeMax) { // suppress "warning: variable length array 'vec' is used [-Wvla]" - FOLLY_PUSH_WARNING; - FOLLY_GCC_DISABLE_WARNING(vla); + FOLLY_PUSH_WARNING + FOLLY_GCC_DISABLE_WARNING("-Wvla") iovec vec[BOOST_PP_IF(FOLLY_HAVE_VLA, count, kSmallSizeMax)]; - FOLLY_POP_WARNING; + FOLLY_POP_WARNING writeChainImpl(callback, vec, count, std::move(buf), flags); } else { diff --git a/folly/test/SingletonBenchmark.cpp b/folly/test/SingletonBenchmark.cpp index 77216766..5c8cd2a0 100644 --- a/folly/test/SingletonBenchmark.cpp +++ b/folly/test/SingletonBenchmark.cpp @@ -24,7 +24,7 @@ #include #include -FOLLY_GCC_DISABLE_WARNING(deprecated-declarations) +FOLLY_GCC_DISABLE_WARNING("-Wdeprecated-declarations") using namespace folly; diff --git a/folly/test/SingletonTest.cpp b/folly/test/SingletonTest.cpp index cf50c687..782f0398 100644 --- a/folly/test/SingletonTest.cpp +++ b/folly/test/SingletonTest.cpp @@ -30,7 +30,7 @@ #include #include -FOLLY_GCC_DISABLE_WARNING(deprecated-declarations) +FOLLY_GCC_DISABLE_WARNING("-Wdeprecated-declarations") using namespace folly; diff --git a/folly/test/SubprocessTest.cpp b/folly/test/SubprocessTest.cpp index b3a0cf6d..07ede20a 100644 --- a/folly/test/SubprocessTest.cpp +++ b/folly/test/SubprocessTest.cpp @@ -33,7 +33,7 @@ #include #include -FOLLY_GCC_DISABLE_WARNING(deprecated-declarations) +FOLLY_GCC_DISABLE_WARNING("-Wdeprecated-declarations") using namespace folly; -- 2.34.1