From: Christopher Dykes Date: Fri, 16 Dec 2016 04:09:21 +0000 (-0800) Subject: Allow folly to compile cleanly with most of the rest of MSVC's sign mismatch warnings X-Git-Tag: v2016.12.19.00~10 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=commitdiff_plain;h=d7d91eb119b9f0758cd7c9e952e9a58209ca5a67 Allow folly to compile cleanly with most of the rest of MSVC's sign mismatch warnings Summary: This allows folly to compile with warnings 4245, 4287 and 4365 enabled, all of which are sign mismatch warnings. This is labeled as 'mostly' because I'll probably have to clean up a few more of these. Reviewed By: yfeldblum Differential Revision: D4263259 fbshipit-source-id: 0db618f0405817503a63094edd75b24ec1e5c9ad --- diff --git a/folly/Bits.h b/folly/Bits.h index 6c794b12..04a1b8ec 100644 --- a/folly/Bits.h +++ b/folly/Bits.h @@ -263,8 +263,11 @@ our_bswap16(Int16 x) { #endif -#define FB_GEN(t, fn) \ -template<> inline t EndianIntBase::swap(t x) { return fn(x); } +#define FB_GEN(t, fn) \ + template <> \ + inline t EndianIntBase::swap(t x) { \ + return t(fn(std::make_unsigned::type(x))); \ + } // fn(x) expands to (x) if the second argument is empty, which is exactly // what we want for [u]int8_t. Also, gcc 4.7 on Intel doesn't have diff --git a/folly/Conv.h b/folly/Conv.h index 37764d24..b034e2ef 100644 --- a/folly/Conv.h +++ b/folly/Conv.h @@ -557,9 +557,10 @@ toAppend(Src value, Tgt * result) { char buffer[20]; if (value < 0) { result->push_back('-'); - result->append(buffer, uint64ToBufferUnsafe(-uint64_t(value), buffer)); + result->append( + buffer, uint64ToBufferUnsafe(uint64_t(-uint64_t(value)), buffer)); } else { - result->append(buffer, uint64ToBufferUnsafe(value, buffer)); + result->append(buffer, uint64ToBufferUnsafe(uint64_t(value), buffer)); } } @@ -681,14 +682,14 @@ toAppend( conv.ToShortest(value, &builder); break; case DoubleToStringConverter::FIXED: - conv.ToFixed(value, numDigits, &builder); + conv.ToFixed(value, int(numDigits), &builder); break; default: CHECK(mode == DoubleToStringConverter::PRECISION); - conv.ToPrecision(value, numDigits, &builder); + conv.ToPrecision(value, int(numDigits), &builder); break; } - const size_t length = builder.position(); + const size_t length = size_t(builder.position()); builder.Finalize(); result->append(buffer, length); } @@ -730,7 +731,9 @@ estimateSpaceNeeded(Src value) { // so 21 is the longest non-exponential number > 1. detail::kConvMaxDecimalInShortestHigh }); - return kMaxPositiveSpace + (value < 0); // +1 for minus sign, if negative + return size_t( + kMaxPositiveSpace + + (value < 0 ? 1 : 0)); // +1 for minus sign, if negative } /** diff --git a/folly/CpuId.h b/folly/CpuId.h index 90848041..26fa1979 100644 --- a/folly/CpuId.h +++ b/folly/CpuId.h @@ -45,13 +45,13 @@ class CpuId { const int n = reg[0]; if (n >= 1) { __cpuid(static_cast(reg), 1); - f1c_ = reg[2]; - f1d_ = reg[3]; + f1c_ = uint32_t(reg[2]); + f1d_ = uint32_t(reg[3]); } if (n >= 7) { __cpuidex(static_cast(reg), 7, 0); - f7b_ = reg[1]; - f7c_ = reg[2]; + f7b_ = uint32_t(reg[1]); + f7c_ = uint32_t(reg[2]); } #elif defined(__i386__) && defined(__PIC__) && !defined(__clang__) && \ defined(__GNUC__) diff --git a/folly/FBString.h b/folly/FBString.h index 7a9252d7..43f4e33e 100644 --- a/folly/FBString.h +++ b/folly/FBString.h @@ -136,7 +136,7 @@ template inline void podFill(Pod* b, Pod* e, T c) { FBSTRING_ASSERT(b && e && b <= e); /*static*/ if (sizeof(T) == 1) { - memset(b, c, e - b); + memset(b, c, size_t(e - b)); } else { auto const ee = b + ((e - b) & ~7u); for (; b != ee; b += 8) { @@ -1184,7 +1184,7 @@ public: // Specialization for const char*, const char* FOLLY_MALLOC_NOINLINE basic_fbstring(const value_type* b, const value_type* e, const A& /*a*/ = A()) - : store_(b, e - b) { + : store_(b, size_type(e - b)) { } // Nonstandard constructor @@ -2705,7 +2705,7 @@ operator<<( } #elif defined(_MSC_VER) // MSVC doesn't define __ostream_insert - os.write(str.data(), str.size()); + os.write(str.data(), std::streamsize(str.size())); #else std::__ostream_insert(os, str.data(), str.size()); #endif diff --git a/folly/FBVector.h b/folly/FBVector.h index 0979f883..1bcc7651 100644 --- a/folly/FBVector.h +++ b/folly/FBVector.h @@ -149,7 +149,7 @@ private: S_destroy_range_a(*this, b_, e_); } - D_deallocate(b_, z_ - b_); + D_deallocate(b_, size_type(z_ - b_)); } } @@ -915,7 +915,7 @@ public: public: size_type size() const noexcept { - return impl_.e_ - impl_.b_; + return size_type(impl_.e_ - impl_.b_); } size_type max_size() const noexcept { @@ -946,7 +946,7 @@ public: } size_type capacity() const noexcept { - return impl_.z_ - impl_.b_; + return size_type(impl_.z_ - impl_.b_); } bool empty() const noexcept { @@ -966,7 +966,7 @@ public: throw; } if (impl_.b_) - M_deallocate(impl_.b_, impl_.z_ - impl_.b_); + M_deallocate(impl_.b_, size_type(impl_.z_ - impl_.b_)); impl_.z_ = newB + newCap; impl_.e_ = newB + (impl_.e_ - impl_.b_); impl_.b_ = newB; diff --git a/folly/Format-inl.h b/folly/Format-inl.h index 7b717363..d116f5a2 100644 --- a/folly/Format-inl.h +++ b/folly/Format-inl.h @@ -174,7 +174,7 @@ void BaseFormatter::operator()(Output& out) auto p = s.begin(); auto end = s.end(); while (p != end) { - auto q = static_cast(memchr(p, '}', end - p)); + auto q = static_cast(memchr(p, '}', size_t(end - p))); if (!q) { out(StringPiece(p, end)); break; @@ -197,7 +197,7 @@ void BaseFormatter::operator()(Output& out) bool hasDefaultArgIndex = false; bool hasExplicitArgIndex = false; while (p != end) { - auto q = static_cast(memchr(p, '{', end - p)); + auto q = static_cast(memchr(p, '{', size_t(end - p))); if (!q) { outputString(StringPiece(p, end)); break; @@ -217,7 +217,7 @@ void BaseFormatter::operator()(Output& out) } // Format string - q = static_cast(memchr(p, '}', end - p)); + q = static_cast(memchr(p, '}', size_t(end - p))); if (q == nullptr) { throw BadFormatArg("folly::format: missing ending '}'"); } @@ -242,7 +242,7 @@ void BaseFormatter::operator()(Output& out) arg.enforce(arg.widthIndex == FormatArg::kNoIndex, "cannot provide width arg index without value arg index"); int sizeArg = nextArg++; - arg.width = getSizeArg(sizeArg, arg); + arg.width = getSizeArg(size_t(sizeArg), arg); } argIndex = nextArg++; @@ -251,7 +251,7 @@ void BaseFormatter::operator()(Output& out) if (arg.width == FormatArg::kDynamicWidth) { arg.enforce(arg.widthIndex != FormatArg::kNoIndex, "cannot provide value arg index without width arg index"); - arg.width = getSizeArg(arg.widthIndex, arg); + arg.width = getSizeArg(size_t(arg.widthIndex), arg); } try { @@ -269,7 +269,7 @@ void BaseFormatter::operator()(Output& out) "folly::format: may not have both default and explicit arg indexes"); } - doFormat(argIndex, arg, out); + doFormat(size_t(argIndex), arg, out); } } @@ -302,7 +302,7 @@ void formatString(StringPiece val, FormatArg& arg, FormatCallback& cb) { if (arg.precision != FormatArg::kDefaultPrecision && val.size() > static_cast(arg.precision)) { - val.reset(val.data(), arg.precision); + val.reset(val.data(), size_t(arg.precision)); } constexpr int padBufSize = 128; @@ -312,7 +312,7 @@ void formatString(StringPiece val, FormatArg& arg, FormatCallback& cb) { auto pad = [&padBuf, &cb, padBufSize] (int chars) { while (chars) { int n = std::min(chars, padBufSize); - cb(StringPiece(padBuf, n)); + cb(StringPiece(padBuf, size_t(n))); chars -= n; } }; @@ -322,7 +322,7 @@ void formatString(StringPiece val, FormatArg& arg, FormatCallback& cb) { val.size() < static_cast(arg.width)) { char fill = arg.fill == FormatArg::kDefaultFill ? ' ' : arg.fill; int padChars = static_cast (arg.width - val.size()); - memset(padBuf, fill, std::min(padBufSize, padChars)); + memset(padBuf, fill, size_t(std::min(padBufSize, padChars))); switch (arg.align) { case FormatArg::Align::DEFAULT: @@ -359,8 +359,8 @@ void formatNumber(StringPiece val, int prefixLen, FormatArg& arg, arg.align = FormatArg::Align::RIGHT; } else if (prefixLen && arg.align == FormatArg::Align::PAD_AFTER_SIGN) { // Split off the prefix, then do any padding if necessary - cb(val.subpiece(0, prefixLen)); - val.advance(prefixLen); + cb(val.subpiece(0, size_t(prefixLen))); + val.advance(size_t(prefixLen)); arg.width = std::max(arg.width - prefixLen, 0); } format_value::formatString(val, arg, cb); @@ -444,7 +444,7 @@ class FormatValue< char sign; if (std::is_signed::value) { if (folly::is_negative(val_)) { - uval = -static_cast(val_); + uval = UT(-static_cast(val_)); sign = '-'; } else { uval = static_cast(val_); @@ -461,7 +461,7 @@ class FormatValue< } } } else { - uval = val_; + uval = static_cast(val_); sign = '\0'; arg.enforce(arg.sign == FormatArg::Sign::DEFAULT, @@ -496,8 +496,11 @@ class FormatValue< int len = snprintf(valBufBegin, (valBuf + valBufSize) - valBufBegin, "%" PRIuMAX, static_cast(uval)); #else - int len = snprintf(valBufBegin, (valBuf + valBufSize) - valBufBegin, - "%ju", static_cast(uval)); + int len = snprintf( + valBufBegin, + size_t((valBuf + valBufSize) - valBufBegin), + "%ju", + static_cast(uval)); #endif // valBufSize should always be big enough, so this should never // happen. @@ -673,7 +676,7 @@ class FormatValue< "invalid specifier '", arg.presentation, "'"); format_value::formatString(val_, arg, cb); } else { - FormatValue(val_.at(arg.splitIntKey())).format(arg, cb); + FormatValue(val_.at(size_t(arg.splitIntKey()))).format(arg, cb); } } diff --git a/folly/Format.h b/folly/Format.h index c34f3339..1b6c8718 100644 --- a/folly/Format.h +++ b/folly/Format.h @@ -211,7 +211,9 @@ class Formatter : public BaseFormatter, template std::ostream& operator<<(std::ostream& out, const Formatter& formatter) { - auto writer = [&out] (StringPiece sp) { out.write(sp.data(), sp.size()); }; + auto writer = [&out](StringPiece sp) { + out.write(sp.data(), std::streamsize(sp.size())); + }; formatter(writer); return out; } diff --git a/folly/FormatArg.h b/folly/FormatArg.h index 89c7e933..33eb2624 100644 --- a/folly/FormatArg.h +++ b/folly/FormatArg.h @@ -243,10 +243,10 @@ inline StringPiece FormatArg::doSplitKey() { const char* p; if (e[-1] == ']') { --e; - p = static_cast(memchr(b, '[', e - b)); + p = static_cast(memchr(b, '[', size_t(e - b))); enforce(p, "unmatched ']'"); } else { - p = static_cast(memchr(b, '.', e - b)); + p = static_cast(memchr(b, '.', size_t(e - b))); } if (p) { key_.assign(p + 1, e); diff --git a/folly/GroupVarint.h b/folly/GroupVarint.h index 70a6fc3c..ae3afdb8 100644 --- a/folly/GroupVarint.h +++ b/folly/GroupVarint.h @@ -102,7 +102,7 @@ class GroupVarint : public detail::GroupVarintBase { * buffer of size bytes. */ static size_t partialCount(const char* p, size_t size) { - char v = *p; + uint8_t v = uint8_t(*p); size_t s = kHeaderSize; s += 1 + b0key(v); if (s > size) return 0; @@ -120,8 +120,9 @@ class GroupVarint : public detail::GroupVarintBase { * return the number of bytes used by the encoding. */ static size_t encodedSize(const char* p) { - return (kHeaderSize + kGroupSize + - b0key(*p) + b1key(*p) + b2key(*p) + b3key(*p)); + return kHeaderSize + kGroupSize + + b0key(uint8_t(*p)) + b1key(uint8_t(*p)) + + b2key(uint8_t(*p)) + b3key(uint8_t(*p)); } /** @@ -194,7 +195,7 @@ class GroupVarint : public detail::GroupVarintBase { * that we must be able to read at least 17 bytes from the input pointer, p. */ static const char* decode(const char* p, uint32_t* dest) { - uint8_t key = p[0]; + uint8_t key = uint8_t(p[0]); __m128i val = _mm_loadu_si128((const __m128i*)(p+1)); __m128i mask = _mm_load_si128((const __m128i*)&detail::groupVarintSSEMasks[key * 2]); @@ -209,7 +210,7 @@ class GroupVarint : public detail::GroupVarintBase { */ static const char* decode(const char* p, uint32_t* a, uint32_t* b, uint32_t* c, uint32_t* d) { - uint8_t key = p[0]; + uint8_t key = uint8_t(p[0]); __m128i val = _mm_loadu_si128((const __m128i*)(p+1)); __m128i mask = _mm_load_si128((const __m128i*)&detail::groupVarintSSEMasks[key * 2]); @@ -217,10 +218,10 @@ class GroupVarint : public detail::GroupVarintBase { // Extracting 32 bits at a time out of an XMM register is a SSE4 feature #if FOLLY_SSE >= 4 - *a = _mm_extract_epi32(r, 0); - *b = _mm_extract_epi32(r, 1); - *c = _mm_extract_epi32(r, 2); - *d = _mm_extract_epi32(r, 3); + *a = uint32_t(_mm_extract_epi32(r, 0)); + *b = uint32_t(_mm_extract_epi32(r, 1)); + *c = uint32_t(_mm_extract_epi32(r, 2)); + *d = uint32_t(_mm_extract_epi32(r, 3)); #else /* !__SSE4__ */ *a = _mm_extract_epi16(r, 0) + (_mm_extract_epi16(r, 1) << 16); *b = _mm_extract_epi16(r, 2) + (_mm_extract_epi16(r, 3) << 16); @@ -274,8 +275,8 @@ class GroupVarint : public detail::GroupVarintBase { */ static size_t size(uint64_t a, uint64_t b, uint64_t c, uint64_t d, uint64_t e) { - return (kHeaderSize + kGroupSize + - key(a) + key(b) + key(c) + key(d) + key(e)); + return kHeaderSize + kGroupSize + + key(a) + key(b) + key(c) + key(d) + key(e); } /** @@ -327,8 +328,8 @@ class GroupVarint : public detail::GroupVarintBase { */ static size_t encodedSize(const char* p) { uint16_t n = loadUnaligned(p); - return (kHeaderSize + kGroupSize + - b0key(n) + b1key(n) + b2key(n) + b3key(n) + b4key(n)); + return kHeaderSize + kGroupSize + + b0key(n) + b1key(n) + b2key(n) + b3key(n) + b4key(n); } /** @@ -338,14 +339,19 @@ class GroupVarint : public detail::GroupVarintBase { */ static char* encode(char* p, uint64_t a, uint64_t b, uint64_t c, uint64_t d, uint64_t e) { - uint8_t b0key = key(a); - uint8_t b1key = key(b); - uint8_t b2key = key(c); - uint8_t b3key = key(d); - uint8_t b4key = key(e); + uint16_t b0key = key(a); + uint16_t b1key = key(b); + uint16_t b2key = key(c); + uint16_t b3key = key(d); + uint16_t b4key = key(e); storeUnaligned( p, - (b4key << 12) | (b3key << 9) | (b2key << 6) | (b1key << 3) | b0key); + uint16_t( + (b4key << 12) | + (b3key << 9) | + (b2key << 6) | + (b1key << 3) | + b0key)); p += 2; storeUnaligned(p, a); p += b0key+1; @@ -412,11 +418,11 @@ class GroupVarint : public detail::GroupVarintBase { return uint8_t(7 - (__builtin_clzll(x | 1) / 8)); } - static uint8_t b0key(uint16_t x) { return x & 7; } - static uint8_t b1key(uint16_t x) { return (x >> 3) & 7; } - static uint8_t b2key(uint16_t x) { return (x >> 6) & 7; } - static uint8_t b3key(uint16_t x) { return (x >> 9) & 7; } - static uint8_t b4key(uint16_t x) { return (x >> 12) & 7; } + static uint8_t b0key(uint16_t x) { return x & 7u; } + static uint8_t b1key(uint16_t x) { return (x >> 3) & 7u; } + static uint8_t b2key(uint16_t x) { return (x >> 6) & 7u; } + static uint8_t b3key(uint16_t x) { return (x >> 9) & 7u; } + static uint8_t b4key(uint16_t x) { return (x >> 12) & 7u; } static const uint64_t kMask[]; }; diff --git a/folly/MPMCQueue.h b/folly/MPMCQueue.h index ce6e54a0..74899ae8 100644 --- a/folly/MPMCQueue.h +++ b/folly/MPMCQueue.h @@ -729,14 +729,14 @@ class MPMCQueueBase> : boost::noncopyable { if (pushes == nextPushes) { // pushTicket_ didn't change from A (or the previous C) to C, // so we can linearize at B (or D) - return pushes - pops; + return ssize_t(pushes - pops); } pushes = nextPushes; uint64_t nextPops = popTicket_.load(std::memory_order_acquire); // D if (pops == nextPops) { // popTicket_ didn't chance from B (or the previous D), so we // can linearize at C - return pushes - pops; + return ssize_t(pushes - pops); } pops = nextPops; } diff --git a/folly/RWSpinLock.h b/folly/RWSpinLock.h index eea433cf..b5effd72 100644 --- a/folly/RWSpinLock.h +++ b/folly/RWSpinLock.h @@ -479,13 +479,14 @@ struct RWTicketIntTrait<64> { #ifdef RW_SPINLOCK_USE_SSE_INSTRUCTIONS_ static __m128i make128(const uint16_t v[4]) { - return _mm_set_epi16(0, 0, 0, 0, v[3], v[2], v[1], v[0]); + return _mm_set_epi16(0, 0, 0, 0, + short(v[3]), short(v[2]), short(v[1]), short(v[0])); } static inline __m128i fromInteger(uint64_t from) { - return _mm_cvtsi64_si128(from); + return _mm_cvtsi64_si128(int64_t(from)); } static inline uint64_t toInteger(__m128i in) { - return _mm_cvtsi128_si64(in); + return uint64_t(_mm_cvtsi128_si64(in)); } static inline uint64_t addParallel(__m128i in, __m128i kDelta) { return toInteger(_mm_add_epi16(in, kDelta)); @@ -501,14 +502,17 @@ struct RWTicketIntTrait<32> { #ifdef RW_SPINLOCK_USE_SSE_INSTRUCTIONS_ static __m128i make128(const uint8_t v[4]) { - return _mm_set_epi8(0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, v[3], v[2], v[1], v[0]); + return _mm_set_epi8( + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + char(v[3]), char(v[2]), char(v[1]), char(v[0])); } static inline __m128i fromInteger(uint32_t from) { - return _mm_cvtsi32_si128(from); + return _mm_cvtsi32_si128(int32_t(from)); } static inline uint32_t toInteger(__m128i in) { - return _mm_cvtsi128_si32(in); + return uint32_t(_mm_cvtsi128_si32(in)); } static inline uint32_t addParallel(__m128i in, __m128i kDelta) { return toInteger(_mm_add_epi8(in, kDelta)); diff --git a/folly/Random.cpp b/folly/Random.cpp index d991990e..8d172fe6 100644 --- a/folly/Random.cpp +++ b/folly/Random.cpp @@ -89,7 +89,7 @@ class BufferedRandomDevice { void getSlow(unsigned char* data, size_t size); inline size_t remaining() const { - return buffer_.get() + bufferSize_ - ptr_; + return size_t(buffer_.get() + bufferSize_ - ptr_); } const size_t bufferSize_; diff --git a/folly/Range.h b/folly/Range.h index 8ab8ae57..e5af94a6 100644 --- a/folly/Range.h +++ b/folly/Range.h @@ -361,7 +361,7 @@ public: // Unfortunately current gcc versions have a bug causing it to reject // this check in a constexpr function: // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71448 - return e_ - b_; + return size_type(e_ - b_); } constexpr size_type walk_size() const { return std::distance(b_, e_); @@ -912,13 +912,13 @@ typedef Range MutableByteRange; inline std::ostream& operator<<(std::ostream& os, const StringPiece piece) { - os.write(piece.start(), piece.size()); + os.write(piece.start(), std::streamsize(piece.size())); return os; } inline std::ostream& operator<<(std::ostream& os, const MutableStringPiece piece) { - os.write(piece.start(), piece.size()); + os.write(piece.start(), std::streamsize(piece.size())); return os; } @@ -1058,7 +1058,7 @@ size_t qfind(const Range& haystack, // Check if done searching if (++j == nsize) { // Yay - return i - haystack.begin(); + return size_t(i - haystack.begin()); } } } diff --git a/folly/SpookyHashV1.h b/folly/SpookyHashV1.h index 2a3d8670..9cfe0299 100644 --- a/folly/SpookyHashV1.h +++ b/folly/SpookyHashV1.h @@ -291,7 +291,7 @@ private: // * is a not-very-regular mix of 1's and 0's // * does not need any other special mathematical properties // - static const uint64_t sc_const = 0xdeadbeefdeadbeefLL; + static const uint64_t sc_const = 0xdeadbeefdeadbeefULL; uint64_t m_data[2*sc_numVars]; // unhashed data, for partial messages uint64_t m_state[sc_numVars]; // internal state of the hash diff --git a/folly/SpookyHashV2.h b/folly/SpookyHashV2.h index 804191d1..7d14069f 100644 --- a/folly/SpookyHashV2.h +++ b/folly/SpookyHashV2.h @@ -296,7 +296,7 @@ private: // * is a not-very-regular mix of 1's and 0's // * does not need any other special mathematical properties // - static constexpr uint64_t sc_const = 0xdeadbeefdeadbeefLL; + static constexpr uint64_t sc_const = 0xdeadbeefdeadbeefULL; uint64_t m_data[2*sc_numVars]; // unhashed data, for partial messages uint64_t m_state[sc_numVars]; // internal state of the hash diff --git a/folly/String.cpp b/folly/String.cpp index 06a7d968..37bc231f 100644 --- a/folly/String.cpp +++ b/folly/String.cpp @@ -575,7 +575,7 @@ std::string stripLeftMargin(std::string s) { piece->end(), [](char c) { return c != ' ' && c != '\t'; }); if (needle != piece->end()) { - indent = std::min(indent, needle - piece->begin()); + indent = std::min(indent, size_t(needle - piece->begin())); } else { max_length = std::max(piece->size(), max_length); } diff --git a/folly/detail/BitsDetail.h b/folly/detail/BitsDetail.h index 06136547..19b0ecbb 100644 --- a/folly/detail/BitsDetail.h +++ b/folly/detail/BitsDetail.h @@ -25,7 +25,7 @@ namespace detail { // (see Bits.cpp) #ifdef _MSC_VER inline int popcount(unsigned int x) { - return __popcnt(x); + return int(__popcnt(x)); } inline int popcountll(unsigned long long x) { return int(__popcnt64(x)); diff --git a/folly/detail/FileUtilDetail.h b/folly/detail/FileUtilDetail.h index 5b70d65f..7ce1f67e 100644 --- a/folly/detail/FileUtilDetail.h +++ b/folly/detail/FileUtilDetail.h @@ -73,10 +73,10 @@ ssize_t wrapFull(F f, int fd, void* buf, size_t count, Offset... offset) { template ssize_t wrapvFull(F f, int fd, iovec* iov, int count, Offset... offset) { ssize_t totalBytes = 0; - size_t r; + ssize_t r; do { r = f(fd, iov, std::min(count, kIovMax), offset...); - if (r == (size_t)-1) { + if (r == -1) { if (errno == EINTR) { continue; } @@ -90,8 +90,8 @@ ssize_t wrapvFull(F f, int fd, iovec* iov, int count, Offset... offset) { totalBytes += r; incr(r, offset...); while (r != 0 && count != 0) { - if (r >= iov->iov_len) { - r -= iov->iov_len; + if (r >= ssize_t(iov->iov_len)) { + r -= ssize_t(iov->iov_len); ++iov; --count; } else { diff --git a/folly/detail/GroupVarintDetail.h b/folly/detail/GroupVarintDetail.h index d44e7995..4a94c7d4 100644 --- a/folly/detail/GroupVarintDetail.h +++ b/folly/detail/GroupVarintDetail.h @@ -30,7 +30,7 @@ struct GroupVarintTraits; template <> struct GroupVarintTraits { - enum { + enum : uint32_t { kGroupSize = 4, kHeaderSize = 1, }; @@ -38,7 +38,7 @@ struct GroupVarintTraits { template <> struct GroupVarintTraits { - enum { + enum : uint32_t { kGroupSize = 5, kHeaderSize = 2, }; @@ -48,7 +48,7 @@ template class GroupVarintBase { protected: typedef GroupVarintTraits Traits; - enum { kHeaderSize = Traits::kHeaderSize }; + enum : uint32_t { kHeaderSize = Traits::kHeaderSize }; public: typedef T type; @@ -56,12 +56,12 @@ class GroupVarintBase { /** * Number of integers encoded / decoded in one pass. */ - enum { kGroupSize = Traits::kGroupSize }; + enum : uint32_t { kGroupSize = Traits::kGroupSize }; /** * Maximum encoded size. */ - enum { kMaxSize = kHeaderSize + sizeof(type) * kGroupSize }; + enum : uint32_t { kMaxSize = kHeaderSize + sizeof(type) * kGroupSize }; /** * Maximum size for n values. diff --git a/folly/detail/RangeCommon.cpp b/folly/detail/RangeCommon.cpp index bcab002a..95c66dc6 100644 --- a/folly/detail/RangeCommon.cpp +++ b/folly/detail/RangeCommon.cpp @@ -41,10 +41,10 @@ size_t qfind_first_byte_of_byteset(const StringPieceLite haystack, const StringPieceLite needles) { SparseByteSet s; for (auto needle: needles) { - s.add(needle); + s.add(uint8_t(needle)); } for (size_t index = 0; index < haystack.size(); ++index) { - if (s.contains(haystack[index])) { + if (s.contains(uint8_t(haystack[index]))) { return index; } } diff --git a/folly/detail/RangeCommon.h b/folly/detail/RangeCommon.h index f7c8a4a5..8eba63e9 100644 --- a/folly/detail/RangeCommon.h +++ b/folly/detail/RangeCommon.h @@ -41,7 +41,7 @@ class StringPieceLite { const char* data() const { return b_; } const char* begin() const { return b_; } const char* end() const { return e_; } - size_t size() const { return e_ - b_; } + size_t size() const { return size_t(e_ - b_); } bool empty() const { return size() == 0; } const char& operator[](size_t i) const { DCHECK_GT(size(), i); return b_[i]; } template diff --git a/folly/detail/TurnSequencer.h b/folly/detail/TurnSequencer.h index 536c2a49..9845eab6 100644 --- a/folly/detail/TurnSequencer.h +++ b/folly/detail/TurnSequencer.h @@ -245,7 +245,9 @@ struct TurnSequencer { /// Returns the bitmask to pass futexWait or futexWake when communicating /// about the specified turn - int futexChannel(uint32_t turn) const noexcept { return 1 << (turn & 31); } + uint32_t futexChannel(uint32_t turn) const noexcept { + return 1u << (turn & 31); + } uint32_t decodeCurrentSturn(uint32_t state) const noexcept { return state & ~kWaitersMask; diff --git a/folly/dynamic-inl.h b/folly/dynamic-inl.h index c1be95b9..09c1b6a7 100644 --- a/folly/dynamic-inl.h +++ b/folly/dynamic-inl.h @@ -288,7 +288,7 @@ struct dynamic::NumericTypeHelper { template::type */> dynamic::dynamic(T t) { type_ = TypeInfo::type; - new (getAddress()) NumericType(t); + new (getAddress()) NumericType(NumericType(t)); } template @@ -507,7 +507,7 @@ inline bool dynamic::empty() const { } inline std::size_t dynamic::count(dynamic const& key) const { - return find(key) != items().end(); + return find(key) != items().end() ? 1u : 0u; } inline dynamic::const_item_iterator dynamic::find(dynamic const& key) const { diff --git a/folly/experimental/Instructions.h b/folly/experimental/Instructions.h index e9ce723f..cc768d55 100644 --- a/folly/experimental/Instructions.h +++ b/folly/experimental/Instructions.h @@ -69,7 +69,7 @@ struct Nehalem : public Default { asm ("popcntq %1, %0" : "=r" (result) : "r" (value)); return result; #else - return _mm_popcnt_u64(value); + return uint64_t(_mm_popcnt_u64(value)); #endif } }; diff --git a/folly/experimental/JSONSchema.cpp b/folly/experimental/JSONSchema.cpp index d73d76b3..81c708dc 100644 --- a/folly/experimental/JSONSchema.cpp +++ b/folly/experimental/JSONSchema.cpp @@ -219,7 +219,7 @@ struct SizeValidator final : IValidator { if (value.type() != type_) { return none; } - if (!Comparison()(length_, value.size())) { + if (!Comparison()(size_t(length_), value.size())) { return makeError("different length string/array/object", value); } return none; diff --git a/folly/fibers/Baton.cpp b/folly/fibers/Baton.cpp index caaaa7f9..01eaf4de 100644 --- a/folly/fibers/Baton.cpp +++ b/folly/fibers/Baton.cpp @@ -57,7 +57,8 @@ void Baton::waitThread() { fiber == NO_WAITER && waitingFiber_.compare_exchange_strong(fiber, THREAD_WAITING))) { do { - folly::detail::MemoryIdler::futexWait(futex_.futex, THREAD_WAITING); + folly::detail::MemoryIdler::futexWait( + futex_.futex, uint32_t(THREAD_WAITING)); fiber = waitingFiber_.load(std::memory_order_acquire); } while (fiber == THREAD_WAITING); } @@ -109,7 +110,7 @@ bool Baton::timedWaitThread(TimeoutController::Duration timeout) { auto deadline = TimeoutController::Clock::now() + timeout; do { const auto wait_rv = - futex_.futex.futexWaitUntil(THREAD_WAITING, deadline); + futex_.futex.futexWaitUntil(uint32_t(THREAD_WAITING), deadline); if (wait_rv == folly::detail::FutexResult::TIMEDOUT) { return false; } diff --git a/folly/fibers/Semaphore.h b/folly/fibers/Semaphore.h index 047abee8..51cca2ca 100644 --- a/folly/fibers/Semaphore.h +++ b/folly/fibers/Semaphore.h @@ -28,7 +28,7 @@ namespace fibers { class Semaphore { public: explicit Semaphore(size_t tokenCount) - : capacity_(tokenCount), tokens_(capacity_) {} + : capacity_(tokenCount), tokens_(int64_t(capacity_)) {} Semaphore(const Semaphore&) = delete; Semaphore(Semaphore&&) = delete; diff --git a/folly/gen/File-inl.h b/folly/gen/File-inl.h index 98981ef9..3d94f8a7 100644 --- a/folly/gen/File-inl.h +++ b/folly/gen/File-inl.h @@ -47,7 +47,7 @@ class FileReader : public GenImpl { if (n == 0) { return true; } - if (!body(ByteRange(buffer_->tail(), n))) { + if (!body(ByteRange(buffer_->tail(), size_t(n)))) { return false; } } @@ -105,7 +105,7 @@ class FileWriter : public Operator { throw std::system_error(errno, std::system_category(), "write() failed"); } - v.advance(n); + v.advance(size_t(n)); } } diff --git a/folly/io/IOBuf.h b/folly/io/IOBuf.h index 66c7cb16..6d9424cd 100644 --- a/folly/io/IOBuf.h +++ b/folly/io/IOBuf.h @@ -507,7 +507,7 @@ class IOBuf { * Returns the number of bytes in the buffer before the start of the data. */ uint64_t headroom() const { - return data_ - buffer(); + return uint64_t(data_ - buffer()); } /** @@ -516,7 +516,7 @@ class IOBuf { * Returns the number of bytes in the buffer after the end of the data. */ uint64_t tailroom() const { - return bufferEnd() - tail(); + return uint64_t(bufferEnd() - tail()); } /** diff --git a/folly/io/RecordIO.cpp b/folly/io/RecordIO.cpp index 37efc51a..8cb081c8 100644 --- a/folly/io/RecordIO.cpp +++ b/folly/io/RecordIO.cpp @@ -95,7 +95,7 @@ void RecordIOReader::Iterator::advanceToValid() { recordAndPos_ = std::make_pair(ByteRange(), off_t(-1)); range_.clear(); // at end } else { - size_t skipped = record.begin() - range_.begin(); + size_t skipped = size_t(record.begin() - range_.begin()); DCHECK_GE(skipped, headerSize()); skipped -= headerSize(); range_.advance(skipped); diff --git a/folly/json.cpp b/folly/json.cpp index 6e807229..882d3bf0 100644 --- a/folly/json.cpp +++ b/folly/json.cpp @@ -735,7 +735,7 @@ void escapeString( out.push_back(hexDigit(v & 0x0f)); } else if (*p == '\\' || *p == '\"') { out.push_back('\\'); - out.push_back(*p++); + out.push_back(char(*p++)); } else if (*p <= 0x1f) { switch (*p) { case '\b': out.append("\\b"); p++; break;