folly: accommodate use of -Wshadow in other projects
authorJim Meyering <meyering@fb.com>
Thu, 13 Jun 2013 16:54:17 +0000 (09:54 -0700)
committerJordan DeLong <jdelong@fb.com>
Wed, 26 Jun 2013 02:45:57 +0000 (19:45 -0700)
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
folly/Format.h
folly/Range.h
folly/experimental/Gen-inl.h
folly/io/IOBuf.h
folly/small_vector.h

index ea15414858e68b5deb0f8f66539c06cc0e824981..a410a186187c8f23909dfccb9e7dba4443a5b505 100644 (file)
 #include <limits>
 #include <type_traits>
 
+// 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 {
index 628a2a29fd0ffbcea69895ebb5e6ad6439ae7298..79a4e705e54c24ed541f947849d4689663befca3 100644 (file)
 #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<containerMode, Args...>& formatter,
 
 #include "folly/Format-inl.h"
 
-#endif /* FOLLY_FORMAT_H_ */
+#pragma GCC diagnostic pop
 
+#endif /* FOLLY_FORMAT_H_ */
index 592aead5cf9bd6f0bc205b390d84d0bd361f486c..21f586da3f7ac1941a66396a3fb3504aad5b26cb 100644 (file)
 #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 T> class Range;
@@ -707,6 +711,8 @@ inline size_t qfind_first_of(const Range<const unsigned char*>& haystack,
 }
 }  // !namespace folly
 
+#pragma GCC diagnostic pop
+
 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_1(folly::Range);
 
 #endif // FOLLY_RANGE_H_
index 39d63fced4e1da1745de5073a133bb1128ae549c..8b0c4dc748e79173dc7b8df62ec1ed19c98d8d8a 100644 (file)
  * 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
index 935f82b6ff51a518621799b9a11f77b90d0e0ae3..3a2fa383b71cafffd38a75543ac5e60c719def24 100644 (file)
 #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_
index 12b6a6de70b7c49f2ea9ec5878493d9ed7b285c9..ed2c44f1ebe8cac78930b7cd10b88e7500209691 100644 (file)
 # 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<T,MaxInline,A,B,C>& a,
 
 }
 
+#pragma GCC diagnostic pop
+
 #ifdef FB_PACKED
 # undef FB_PACKED
 #endif