Summary:
Truncations should be explicit, but for some reason, MSVC seems to be the only compiler that will warn you when you implicitly truncate integer or float values.
This allows Folly to be compiled with warnings 4018, 4242, 4244 and 4305 enabled.
Technically 4018 is a sign mismatch warning, but there was only one place it was being triggered so I included it anyways. The other 3 are warnings for implicit truncation.
There is one other implicit truncation warning that currently triggers in Folly, 4267, but there are a lot more places where that triggers so I'll do that in a separate diff.
Reviewed By: yfeldblum
Differential Revision:
D4249471
fbshipit-source-id:
e18a93d85856c998576934a6229c9edd1638a54e
UT result = 0;
for (; e - b >= 4; b += 4) {
- result *= 10000;
+ result *= static_cast<UT>(10000);
const int32_t r0 = shift1000[static_cast<size_t>(b[0])];
const int32_t r1 = shift100[static_cast<size_t>(b[1])];
const int32_t r2 = shift10[static_cast<size_t>(b[2])];
if (sum >= OOR) {
goto outOfRange;
}
- result += sum;
+ result += UT(sum);
}
switch (e - b) {
} else {
throw std::invalid_argument("Unknown address family");
}
- return {IPAddress(0), 0};
+ return {IPAddress(0), uint8_t(0)};
}
[[noreturn]] void IPAddress::asV4Throw() const {
if (other.getFamily() != getFamily()) {
return false;
}
- int mask_length = 128;
+ uint8_t mask_length = 128;
switch (getFamily()) {
case AF_INET:
mask_length = 32;
template <class String>
void toLower(String& s) {
for (auto& c : s) {
- c = tolower(c);
+ c = char(tolower(c));
}
}
return __popcnt(x);
}
inline int popcountll(unsigned long long x) {
- return __popcnt64(x);
+ return int(__popcnt64(x));
}
#elif defined(__POPCNT__)
}
inline void incr(ssize_t /* n */) {}
-inline void incr(ssize_t n, off_t& offset) { offset += n; }
+inline void incr(ssize_t n, off_t& offset) { offset += off_t(n); }
// Wrap call to read/pread/write/pwrite(fd, buf, count, offset?) to retry on
// incomplete reads / writes. The variadic argument magic is there to support
// compute the length
auto len = q.chainLength();
- if (len > std::numeric_limits<int64_t>::max()) {
+ if (len > uint64_t(std::numeric_limits<int64_t>::max())) {
throw std::range_error(folly::to<std::string>(
"serialized data size ", len, " is too large to represent as BSER"));
}
}
char c = '\0';
if (match.length(2) != 0) {
- c = tolower(value[match.position(2)]);
+ c = char(tolower(value[match.position(2)]));
}
StringPiece numStr(value.data() + match.position(1), match.length(1));
size_t size = to<size_t>(numStr);
currentOp->iov_len -= partialBytes_;
// Increment the totalBytesWritten_ count by bytesWritten_;
- totalBytesWritten_ += bytesWritten_;
+ assert(bytesWritten_ >= 0);
+ totalBytesWritten_ += uint32_t(bytesWritten_);
}
private:
}
std::string decodeUnicodeEscape(Input& in) {
- auto hexVal = [&] (char c) -> unsigned {
+ auto hexVal = [&] (int c) -> uint16_t {
return c >= '0' && c <= '9' ? c - '0' :
c >= 'a' && c <= 'f' ? c - 'a' + 10 :
c >= 'A' && c <= 'F' ? c - 'A' + 10 :
in.error("null byte in string");
}
- ret.push_back(*in);
+ ret.push_back(char(*in));
++in;
}