folly: adjust more headers to be -Wshadow-clean
authorJim Meyering <meyering@fb.com>
Sat, 24 Aug 2013 02:46:09 +0000 (19:46 -0700)
committerSara Golemon <sgolemon@fb.com>
Wed, 28 Aug 2013 21:30:13 +0000 (14:30 -0700)
Summary:
This is part of what's required to make mcrouter compile warning-free
with gcc -Wshadow.  In case it's not obvious why this is worth doing,
see t2719164.

I've used two techniques:
rename one of the shadowed variables
bracket offending code with #pragma directives to disable the warning there.

* folly/Bits.h (BitIterator): Guard this function with #pragma
to avoid a warning about its member-shadowing "bitOffset" parameter.
* folly/Memory.h (StlAllocator): Rename parameter in trivial, one-line
function definition, s/alloc/a/, to avoid shadowing the member function.
Let me know if you'd prefer #pragma directives instead.
* folly/io/Cursor.h (pull,skip,clone): Rename parameter, s/length/len/,
not to shadow the member function name.

Test Plan:
build and run tests of a few tools that use these headers

Reviewed By: jon.coens@fb.com

FB internal diff: D940493

folly/Bits.h
folly/Memory.h
folly/io/Cursor.h

index 6b2fef765466d82273d968b23dd9308b2b21ad30..58833106ebe031a258dd2722d06338e3d1b10837 100644 (file)
@@ -385,11 +385,14 @@ class BitIterator
    * Construct a BitIterator that points at a given bit offset (default 0)
    * in iter.
    */
+  #pragma GCC diagnostic push // bitOffset shadows a member
+  #pragma GCC diagnostic ignored "-Wshadow"
   explicit BitIterator(const BaseIter& iter, size_t bitOffset=0)
     : bititerator_detail::BitIteratorBase<BaseIter>::type(iter),
       bitOffset_(bitOffset) {
     assert(bitOffset_ < bitsPerBlock());
   }
+  #pragma GCC diagnostic pop
 
   size_t bitOffset() const {
     return bitOffset_;
@@ -553,4 +556,3 @@ inline void storeUnaligned(void* p, T value) {
 }  // namespace folly
 
 #endif /* FOLLY_BITS_H_ */
-
index 5a1059bd5fa70fa09449bb4f22556d26e971fbc5..ce2573d3c03fef88e3b4f404ee6e6a041bd927d1 100644 (file)
@@ -91,7 +91,7 @@ template <class Alloc> class StlAllocator<Alloc, void> {
   typedef const void* const_pointer;
 
   StlAllocator() : alloc_(nullptr) { }
-  explicit StlAllocator(Alloc* alloc) : alloc_(alloc) { }
+  explicit StlAllocator(Alloc* a) : alloc_(a) { }
 
   Alloc* alloc() const {
     return alloc_;
@@ -126,7 +126,7 @@ class StlAllocator {
   typedef size_t size_type;
 
   StlAllocator() : alloc_(nullptr) { }
-  explicit StlAllocator(Alloc* alloc) : alloc_(alloc) { }
+  explicit StlAllocator(Alloc* a) : alloc_(a) { }
 
   template <class U> StlAllocator(const StlAllocator<Alloc, U>& other)
     : alloc_(other.alloc()) { }
index ce73705125957ec1ddb4d33a502b98d337326f72..79fd4cc789f0c4a3b2b70d92f1142f774cd1d42e 100644 (file)
@@ -192,20 +192,20 @@ class CursorBase {
     return std::make_pair(data(), available);
   }
 
-  void pull(void* buf, size_t length) {
-    if (UNLIKELY(pullAtMost(buf, length) != length)) {
+  void pull(void* buf, size_t len) {
+    if (UNLIKELY(pullAtMost(buf, len) != len)) {
       throw std::out_of_range("underflow");
     }
   }
 
-  void clone(std::unique_ptr<folly::IOBuf>& buf, size_t length) {
-    if (UNLIKELY(cloneAtMost(buf, length) != length)) {
+  void clone(std::unique_ptr<folly::IOBuf>& buf, size_t len) {
+    if (UNLIKELY(cloneAtMost(buf, len) != len)) {
       throw std::out_of_range("underflow");
     }
   }
 
-  void skip(size_t length) {
-    if (UNLIKELY(skipAtMost(length) != length)) {
+  void skip(size_t len) {
+    if (UNLIKELY(skipAtMost(len) != len)) {
       throw std::out_of_range("underflow");
     }
   }