Skip to content

Commit

Permalink
More MSVC Warnings Fixes
Browse files Browse the repository at this point in the history
Summary: This fixes up a couple more MSVC warnings I ran into when trying to update the OSS React Native Windows build to a newer version of Folly. Specifically, another instance of C4146 "unary minus operator applied to unsigned type, result still unsigned", and a couple instances of C4244 "conversion from 'type1' to 'type2', possible loss of data"

Differential Revision: D50383545
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Oct 17, 2023
1 parent b518be8 commit cf13cdf
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
30 changes: 29 additions & 1 deletion folly/ConstexprMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,10 @@ constexpr T constexpr_mult(T const a, T const b) {

namespace detail {

template <typename T, typename E>
template <
typename T,
typename E,
std::enable_if_t<std::is_signed<E>::value, int> = 1>
constexpr T constexpr_ipow(T const base, E const exp) {
if (std::is_floating_point<T>::value) {
if (exp < E(0)) {
Expand All @@ -485,6 +488,31 @@ constexpr T constexpr_ipow(T const base, E const exp) {
return constexpr_mult(constexpr_mult(div, div), rem);
}

template <
typename T,
typename E,
std::enable_if_t<std::is_unsigned<E>::value, int> = 1>
constexpr T constexpr_ipow(T const base, E const exp) {
if (std::is_floating_point<T>::value) {
if (exp == E(0)) {
return T(1);
}
if (constexpr_isnan(base)) {
return base;
}
}
if (exp == E(0)) {
return T(1);
}
if (exp == E(1)) {
return base;
}
auto const hexp = constexpr_trunc(exp / E(2));
auto const div = constexpr_ipow(base, hexp);
auto const rem = hexp * E(2) == exp ? T(1) : base;
return constexpr_mult(constexpr_mult(div, div), rem);
}

} // namespace detail

/// constexpr_exp
Expand Down
3 changes: 2 additions & 1 deletion folly/concurrency/CacheLocality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,8 @@ class SimpleAllocator {
// leave pointers that could hide leaks at shutdown, since the backing
// slabs may not be deallocated if the instance is a leaky singleton.
auto* base = static_cast<char*>(ptr);
std::fill(base + sizeof(void*), base + allocator->sz_, 0);
std::fill(
base + sizeof(void*), base + allocator->sz_, static_cast<char>(0));
}
allocator->freelist_ = ptr;
}
Expand Down
2 changes: 1 addition & 1 deletion folly/hash/Hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ struct integral_hasher {
auto const u = to_unsigned(i);
auto const hi = static_cast<uint64_t>(u >> sizeof(Int) * 4);
auto const lo = static_cast<uint64_t>(u);
return hash::hash_128_to_64(hi, lo);
return static_cast<size_t>(hash::hash_128_to_64(hi, lo));
}
}
};
Expand Down

0 comments on commit cf13cdf

Please sign in to comment.