From 46de7098b46d000be284450d582c14608cab6f93 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 13 Jun 2013 09:54:17 -0700 Subject: [PATCH] folly: accommodate use of -Wshadow in other projects Summary: Without this change, any folly-using project that attempts to enable gcc's -Wshadow option will be overwhelmed by warnings about violations in folly's class definitions. Violations are often due to local variable or parameter names shadowed by a member function. Bracket offending content with directives like this: #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wshadow" ... #pragma GCC diagnostic pop This set of modified files is the minimal set to allow tao to use -Wshadow with no folly-related warning. Test Plan: fbmake folly/test && fbmake opt Reviewed By: simpkins@fb.com FB internal diff: D848455 --- folly/FBString.h | 6 ++++++ folly/Format.h | 7 ++++++- folly/Range.h | 6 ++++++ folly/experimental/Gen-inl.h | 6 ++++++ folly/io/IOBuf.h | 6 ++++++ folly/small_vector.h | 6 ++++++ 6 files changed, 36 insertions(+), 1 deletion(-) diff --git a/folly/FBString.h b/folly/FBString.h index ea154148..a410a186 100644 --- a/folly/FBString.h +++ b/folly/FBString.h @@ -101,6 +101,10 @@ #include #include +// Ignore shadowing warnings within this file, so includers can use -Wshadow. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wshadow" + #ifdef _LIBSTDCXX_FBSTRING namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION @@ -2323,6 +2327,8 @@ _GLIBCXX_END_NAMESPACE_VERSION } // namespace folly +#pragma GCC diagnostic pop + #ifndef _LIBSTDCXX_FBSTRING namespace std { diff --git a/folly/Format.h b/folly/Format.h index 628a2a29..79a4e705 100644 --- a/folly/Format.h +++ b/folly/Format.h @@ -36,6 +36,10 @@ #include "folly/small_vector.h" #include "folly/FormatArg.h" +// Ignore shadowing warnings within this file, so includers can use -Wshadow. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wshadow" + namespace folly { // forward declarations @@ -268,5 +272,6 @@ void formatFormatter(const Formatter& formatter, #include "folly/Format-inl.h" -#endif /* FOLLY_FORMAT_H_ */ +#pragma GCC diagnostic pop +#endif /* FOLLY_FORMAT_H_ */ diff --git a/folly/Range.h b/folly/Range.h index 592aead5..21f586da 100644 --- a/folly/Range.h +++ b/folly/Range.h @@ -35,6 +35,10 @@ #include "folly/Traits.h" #include "folly/Likely.h" +// Ignore shadowing warnings within this file, so includers can use -Wshadow. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wshadow" + namespace folly { template class Range; @@ -707,6 +711,8 @@ inline size_t qfind_first_of(const Range& haystack, } } // !namespace folly +#pragma GCC diagnostic pop + FOLLY_ASSUME_FBVECTOR_COMPATIBLE_1(folly::Range); #endif // FOLLY_RANGE_H_ diff --git a/folly/experimental/Gen-inl.h b/folly/experimental/Gen-inl.h index 39d63fce..8b0c4dc7 100644 --- a/folly/experimental/Gen-inl.h +++ b/folly/experimental/Gen-inl.h @@ -14,6 +14,10 @@ * limitations under the License. */ +// Ignore shadowing warnings within this file, so includers can use -Wshadow. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wshadow" + namespace folly { namespace gen { /** @@ -1829,3 +1833,5 @@ inline detail::Skip skip(size_t count) { } }} //folly::gen + +#pragma GCC diagnostic pop diff --git a/folly/io/IOBuf.h b/folly/io/IOBuf.h index 935f82b6..3a2fa383 100644 --- a/folly/io/IOBuf.h +++ b/folly/io/IOBuf.h @@ -34,6 +34,10 @@ #include "folly/Range.h" #include "folly/FBVector.h" +// Ignore shadowing warnings within this file, so includers can use -Wshadow. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wshadow" + namespace folly { /** @@ -1214,4 +1218,6 @@ inline IOBuf::Iterator IOBuf::end() const { return cend(); } } // folly +#pragma GCC diagnostic pop + #endif // FOLLY_IO_IOBUF_H_ diff --git a/folly/small_vector.h b/folly/small_vector.h index 12b6a6de..ed2c44f1 100644 --- a/folly/small_vector.h +++ b/folly/small_vector.h @@ -64,6 +64,10 @@ # endif #endif +// Ignore shadowing warnings within this file, so includers can use -Wshadow. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wshadow" + namespace folly { ////////////////////////////////////////////////////////////////////// @@ -1180,6 +1184,8 @@ void swap(small_vector& a, } +#pragma GCC diagnostic pop + #ifdef FB_PACKED # undef FB_PACKED #endif -- 2.34.1