Commit 820c91a0 authored by Jim Meyering's avatar Jim Meyering Committed by Sara Golemon

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
parent cf0e5923
...@@ -385,11 +385,14 @@ class BitIterator ...@@ -385,11 +385,14 @@ class BitIterator
* Construct a BitIterator that points at a given bit offset (default 0) * Construct a BitIterator that points at a given bit offset (default 0)
* in iter. * in iter.
*/ */
#pragma GCC diagnostic push // bitOffset shadows a member
#pragma GCC diagnostic ignored "-Wshadow"
explicit BitIterator(const BaseIter& iter, size_t bitOffset=0) explicit BitIterator(const BaseIter& iter, size_t bitOffset=0)
: bititerator_detail::BitIteratorBase<BaseIter>::type(iter), : bititerator_detail::BitIteratorBase<BaseIter>::type(iter),
bitOffset_(bitOffset) { bitOffset_(bitOffset) {
assert(bitOffset_ < bitsPerBlock()); assert(bitOffset_ < bitsPerBlock());
} }
#pragma GCC diagnostic pop
size_t bitOffset() const { size_t bitOffset() const {
return bitOffset_; return bitOffset_;
...@@ -553,4 +556,3 @@ inline void storeUnaligned(void* p, T value) { ...@@ -553,4 +556,3 @@ inline void storeUnaligned(void* p, T value) {
} // namespace folly } // namespace folly
#endif /* FOLLY_BITS_H_ */ #endif /* FOLLY_BITS_H_ */
...@@ -91,7 +91,7 @@ template <class Alloc> class StlAllocator<Alloc, void> { ...@@ -91,7 +91,7 @@ template <class Alloc> class StlAllocator<Alloc, void> {
typedef const void* const_pointer; typedef const void* const_pointer;
StlAllocator() : alloc_(nullptr) { } StlAllocator() : alloc_(nullptr) { }
explicit StlAllocator(Alloc* alloc) : alloc_(alloc) { } explicit StlAllocator(Alloc* a) : alloc_(a) { }
Alloc* alloc() const { Alloc* alloc() const {
return alloc_; return alloc_;
...@@ -126,7 +126,7 @@ class StlAllocator { ...@@ -126,7 +126,7 @@ class StlAllocator {
typedef size_t size_type; typedef size_t size_type;
StlAllocator() : alloc_(nullptr) { } StlAllocator() : alloc_(nullptr) { }
explicit StlAllocator(Alloc* alloc) : alloc_(alloc) { } explicit StlAllocator(Alloc* a) : alloc_(a) { }
template <class U> StlAllocator(const StlAllocator<Alloc, U>& other) template <class U> StlAllocator(const StlAllocator<Alloc, U>& other)
: alloc_(other.alloc()) { } : alloc_(other.alloc()) { }
......
...@@ -192,20 +192,20 @@ class CursorBase { ...@@ -192,20 +192,20 @@ class CursorBase {
return std::make_pair(data(), available); return std::make_pair(data(), available);
} }
void pull(void* buf, size_t length) { void pull(void* buf, size_t len) {
if (UNLIKELY(pullAtMost(buf, length) != length)) { if (UNLIKELY(pullAtMost(buf, len) != len)) {
throw std::out_of_range("underflow"); throw std::out_of_range("underflow");
} }
} }
void clone(std::unique_ptr<folly::IOBuf>& buf, size_t length) { void clone(std::unique_ptr<folly::IOBuf>& buf, size_t len) {
if (UNLIKELY(cloneAtMost(buf, length) != length)) { if (UNLIKELY(cloneAtMost(buf, len) != len)) {
throw std::out_of_range("underflow"); throw std::out_of_range("underflow");
} }
} }
void skip(size_t length) { void skip(size_t len) {
if (UNLIKELY(skipAtMost(length) != length)) { if (UNLIKELY(skipAtMost(len) != len)) {
throw std::out_of_range("underflow"); throw std::out_of_range("underflow");
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment