Fix warnings with msvc. (#225)

* Fix warnings with msvc.

* Fix more warnings.
This commit is contained in:
Gregory Popovitch
2023-12-09 12:23:51 -05:00
committed by GitHub
parent d3f0b986bf
commit 946ebad67a
3 changed files with 17 additions and 9 deletions
+2 -2
View File
@@ -357,7 +357,7 @@ inline size_t H1(size_t hashval, const ctrl_t* ) {
#endif #endif
inline h2_t H2(size_t hashval) { return (h2_t)(ctrl_t)(hashval & 0x7F); } inline ctrl_t H2(size_t hashval) { return (ctrl_t)(hashval & 0x7F); }
inline bool IsEmpty(ctrl_t c) { return c == kEmpty; } inline bool IsEmpty(ctrl_t c) { return c == kEmpty; }
inline bool IsFull(ctrl_t c) { return c >= static_cast<ctrl_t>(0); } inline bool IsFull(ctrl_t c) { return c >= static_cast<ctrl_t>(0); }
@@ -4582,7 +4582,7 @@ struct HashtableDebugAccess<Set, typename std::enable_if<has_member_type_raw_has
auto seq = set.probe(hashval); auto seq = set.probe(hashval);
while (true) { while (true) {
priv::Group g{set.ctrl_ + seq.offset()}; priv::Group g{set.ctrl_ + seq.offset()};
for (uint32_t i : g.Match(priv::H2(hashval))) { for (uint32_t i : g.Match((h2_t)priv::H2(hashval))) {
if (Traits::apply( if (Traits::apply(
typename Set::template EqualElement<typename Set::key_type>{ typename Set::template EqualElement<typename Set::key_type>{
key, set.eq_ref()}, key, set.eq_ref()},
+5 -5
View File
@@ -276,7 +276,7 @@ PHMAP_BASE_INTERNAL_FORCEINLINE uint32_t CountLeadingZeros64Slow(uint64_t n) {
if (n >> 16) zeroes -= 16, n >>= 16; if (n >> 16) zeroes -= 16, n >>= 16;
if (n >> 8) zeroes -= 8, n >>= 8; if (n >> 8) zeroes -= 8, n >>= 8;
if (n >> 4) zeroes -= 4, n >>= 4; if (n >> 4) zeroes -= 4, n >>= 4;
return "\4\3\2\2\1\1\1\1\0\0\0\0\0\0\0"[n] + zeroes; return (uint32_t)("\4\3\2\2\1\1\1\1\0\0\0\0\0\0\0"[n] + zeroes);
} }
PHMAP_BASE_INTERNAL_FORCEINLINE uint32_t CountLeadingZeros64(uint64_t n) { PHMAP_BASE_INTERNAL_FORCEINLINE uint32_t CountLeadingZeros64(uint64_t n) {
@@ -284,17 +284,17 @@ PHMAP_BASE_INTERNAL_FORCEINLINE uint32_t CountLeadingZeros64(uint64_t n) {
// MSVC does not have __buitin_clzll. Use _BitScanReverse64. // MSVC does not have __buitin_clzll. Use _BitScanReverse64.
unsigned long result = 0; // NOLINT(runtime/int) unsigned long result = 0; // NOLINT(runtime/int)
if (_BitScanReverse64(&result, n)) { if (_BitScanReverse64(&result, n)) {
return (int)(63 - result); return (uint32_t)(63 - result);
} }
return 64; return 64;
#elif defined(_MSC_VER) && !defined(__clang__) #elif defined(_MSC_VER) && !defined(__clang__)
// MSVC does not have __buitin_clzll. Compose two calls to _BitScanReverse // MSVC does not have __buitin_clzll. Compose two calls to _BitScanReverse
unsigned long result = 0; // NOLINT(runtime/int) unsigned long result = 0; // NOLINT(runtime/int)
if ((n >> 32) && _BitScanReverse(&result, (unsigned long)(n >> 32))) { if ((n >> 32) && _BitScanReverse(&result, (unsigned long)(n >> 32))) {
return 31 - result; return (uint32_t)(31 - result);
} }
if (_BitScanReverse(&result, (unsigned long)n)) { if (_BitScanReverse(&result, (unsigned long)n)) {
return 63 - result; return (uint32_t)(63 - result);
} }
return 64; return 64;
#elif defined(__GNUC__) || defined(__clang__) #elif defined(__GNUC__) || defined(__clang__)
@@ -309,7 +309,7 @@ PHMAP_BASE_INTERNAL_FORCEINLINE uint32_t CountLeadingZeros64(uint64_t n) {
if (n == 0) { if (n == 0) {
return 64; return 64;
} }
return __builtin_clzll(n); return (uint32_t)__builtin_clzll(n);
#else #else
return CountLeadingZeros64Slow(n); return CountLeadingZeros64Slow(n);
#endif #endif
+10 -2
View File
@@ -169,8 +169,12 @@ public:
ofs_.open(file_path, std::ofstream::out | std::ofstream::trunc | std::ofstream::binary); ofs_.open(file_path, std::ofstream::out | std::ofstream::trunc | std::ofstream::binary);
} }
~BinaryOutputArchive() = default;
BinaryOutputArchive(const BinaryOutputArchive&) = delete;
BinaryOutputArchive& operator=(const BinaryOutputArchive&) = delete;
bool saveBinary(const void *p, size_t sz) { bool saveBinary(const void *p, size_t sz) {
ofs_.write(reinterpret_cast<const char*>(p), sz); ofs_.write(reinterpret_cast<const char*>(p), (std::streamsize)sz);
return true; return true;
} }
@@ -197,9 +201,13 @@ public:
BinaryInputArchive(const char * file_path) { BinaryInputArchive(const char * file_path) {
ifs_.open(file_path, std::ofstream::in | std::ofstream::binary); ifs_.open(file_path, std::ofstream::in | std::ofstream::binary);
} }
~BinaryInputArchive() = default;
BinaryInputArchive(const BinaryInputArchive&) = delete;
BinaryInputArchive& operator=(const BinaryInputArchive&) = delete;
bool loadBinary(void* p, size_t sz) { bool loadBinary(void* p, size_t sz) {
ifs_.read(reinterpret_cast<char*>(p), sz); ifs_.read(reinterpret_cast<char*>(p), (std::streamsize)sz);
return true; return true;
} }