From 820c91a0f9cb1d5c7938a6e9394e625781919772 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Fri, 23 Aug 2013 19:46:09 -0700 Subject: [PATCH] folly: adjust more headers to be -Wshadow-clean 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 | 4 +++- folly/Memory.h | 4 ++-- folly/io/Cursor.h | 12 ++++++------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/folly/Bits.h b/folly/Bits.h index 6b2fef76..58833106 100644 --- a/folly/Bits.h +++ b/folly/Bits.h @@ -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::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_ */ - diff --git a/folly/Memory.h b/folly/Memory.h index 5a1059bd..ce2573d3 100644 --- a/folly/Memory.h +++ b/folly/Memory.h @@ -91,7 +91,7 @@ template class StlAllocator { 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 StlAllocator(const StlAllocator& other) : alloc_(other.alloc()) { } diff --git a/folly/io/Cursor.h b/folly/io/Cursor.h index ce737051..79fd4cc7 100644 --- a/folly/io/Cursor.h +++ b/folly/io/Cursor.h @@ -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& buf, size_t length) { - if (UNLIKELY(cloneAtMost(buf, length) != length)) { + void clone(std::unique_ptr& 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"); } } -- 2.34.1