cleanup warnings up to /w4 for msvc in btree.h

This commit is contained in:
greg
2019-12-31 14:50:08 -05:00
parent 5e40c675e1
commit 1ae11ca382
2 changed files with 47 additions and 23 deletions
+46 -23
View File
@@ -66,6 +66,24 @@
#define PHMAP_META_INTERNAL_STD_CONSTRUCTION_TRAITS_DONT_CHECK_DESTRUCTION 1
#endif
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4127) // conditional expression is constant
#pragma warning(disable : 4324) // structure was padded due to alignment specifier
#pragma warning(disable : 4355) // 'this': used in base member initializer list
#pragma warning(disable : 4514) // unreferenced inline function has been removed
#pragma warning(disable : 4623) // default constructor was implicitly defined as deleted
#pragma warning(disable : 4625) // copy constructor was implicitly defined as deleted
#pragma warning(disable : 4626) // assignment operator was implicitly defined as deleted
#pragma warning(disable : 4710) // function not inlined
#pragma warning(disable : 4711) // selected for automatic inline expansion
#pragma warning(disable : 4820) // '6' bytes padding added after data member
#pragma warning(disable : 4868) // compiler may not enforce left-to-right evaluation order in braced initializer list
#pragma warning(disable : 5026) // move constructor was implicitly defined as deleted
#pragma warning(disable : 5027) // move assignment operator was implicitly defined as deleted
#pragma warning(disable : 5045) // Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified
#endif
namespace phmap {
@@ -1063,7 +1081,7 @@ namespace container_internal {
constexpr static size_type Alignment() {
static_assert(LeafLayout(1).Alignment() == InternalLayout().Alignment(),
"Alignment of all nodes must be equal.");
return InternalLayout().Alignment();
return (size_type)InternalLayout().Alignment();
}
protected:
@@ -1073,15 +1091,15 @@ namespace container_internal {
using layout_type = phmap::container_internal::Layout<btree_node *, field_type,
slot_type, btree_node *>;
constexpr static size_type SizeWithNValues(size_type n) {
return layout_type(/*parent*/ 1,
return (size_type)layout_type(/*parent*/ 1,
/*position, start, count, max_count*/ 4,
/*values*/ n,
/*values*/ (size_t)n,
/*children*/ 0)
.AllocSize();
}
// A lower bound for the overhead of fields other than values in a leaf node.
constexpr static size_type MinimumOverhead() {
return SizeWithNValues(1) - sizeof(value_type);
return (size_type)(SizeWithNValues(1) - sizeof(value_type));
}
// Compute how many values we can fit onto a leaf node taking into account
@@ -1112,7 +1130,7 @@ namespace container_internal {
constexpr static layout_type LeafLayout(const int max_values = kNodeValues) {
return layout_type(/*parent*/ 1,
/*position, start, count, max_count*/ 4,
/*values*/ max_values,
/*values*/ (size_t)max_values,
/*children*/ 0);
}
constexpr static layout_type InternalLayout() {
@@ -1122,10 +1140,10 @@ namespace container_internal {
/*children*/ kNodeValues + 1);
}
constexpr static size_type LeafSize(const int max_values = kNodeValues) {
return LeafLayout(max_values).AllocSize();
return (size_type)LeafLayout(max_values).AllocSize();
}
constexpr static size_type InternalSize() {
return InternalLayout().AllocSize();
return (size_type)InternalLayout().AllocSize();
}
// N is the index of the type in the Layout definition.
@@ -1337,7 +1355,7 @@ namespace container_internal {
// Removes the values at positions [i, i + to_erase), shifting all values
// after that range to the left by to_erase. Does not change children at all.
void remove_values_ignore_children(int i, int to_erase,
void remove_values_ignore_children(int i, size_type to_erase,
allocator_type *alloc);
// Rebalances a node with its right sibling.
@@ -1363,7 +1381,7 @@ namespace container_internal {
n->set_position(0);
n->set_start(0);
n->set_count(0);
n->set_max_count(max_count);
n->set_max_count((field_type)max_count);
phmap::container_internal::SanitizerPoisonMemoryRegion(
n->slot(0), max_count * sizeof(slot_type));
return n;
@@ -1951,7 +1969,7 @@ namespace container_internal {
node_type *allocate(const size_type size) {
return reinterpret_cast<node_type *>(
phmap::container_internal::Allocate<node_type::Alignment()>(
mutable_allocator(), size));
mutable_allocator(), (size_t)size));
}
// Node creation/deletion routines.
@@ -1976,7 +1994,7 @@ namespace container_internal {
// Deallocates a node of a certain size in bytes using the allocator.
void deallocate(const size_type size, node_type *node) {
phmap::container_internal::Deallocate<node_type::Alignment()>(
mutable_allocator(), node, size);
mutable_allocator(), node, (size_t)size);
}
void delete_internal_node(node_type *node) {
@@ -2116,7 +2134,7 @@ namespace container_internal {
value_destroy(i, alloc);
}
value_init(i, alloc, std::forward<Args>(args)...);
set_count(count() + 1);
set_count((field_type)(count() + 1));
if (!leaf() && count() > i + 1) {
for (int j = count(); j > i + 1; --j) {
@@ -2141,10 +2159,10 @@ namespace container_internal {
template <typename P>
inline void btree_node<P>::remove_values_ignore_children(
const int i, const int to_erase, allocator_type *alloc) {
int i, size_type to_erase, allocator_type *alloc) {
params_type::move(alloc, slot(i + to_erase), slot(count()), slot(i));
value_destroy_n(count() - to_erase, to_erase, alloc);
set_count(count() - to_erase);
set_count((field_type)(count() - to_erase));
}
template <typename P>
@@ -2187,8 +2205,8 @@ namespace container_internal {
}
// Fixup the counts on the left and right nodes.
set_count(count() + to_move);
right->set_count(right->count() - to_move);
set_count((field_type)(count() + to_move));
right->set_count((field_type)(right->count() - to_move));
}
template <typename P>
@@ -2266,8 +2284,8 @@ namespace container_internal {
}
// Fixup the counts on the left and right nodes.
set_count(count() - to_move);
right->set_count(right->count() + to_move);
set_count((field_type)(count() - to_move));
right->set_count((field_type)(right->count() + to_move));
}
template <typename P>
@@ -2281,13 +2299,13 @@ namespace container_internal {
// more values on the right node. If we're inserting at the end of the
// right node then bias the split to put more values on the left node.
if (insert_position == 0) {
dest->set_count(count() - 1);
dest->set_count((field_type)(count() - 1));
} else if (insert_position == kNodeValues) {
dest->set_count(0);
} else {
dest->set_count(count() / 2);
dest->set_count((field_type)(count() / 2));
}
set_count(count() - dest->count());
set_count((field_type)(count() - dest->count()));
assert(count() >= 1);
// Move values from the left sibling to the right sibling.
@@ -2297,7 +2315,7 @@ namespace container_internal {
value_destroy_n(count(), dest->count(), alloc);
// The split key is the largest value in the left sibling.
set_count(count() - 1);
set_count((field_type)(count() - 1));
parent()->emplace_value(position(), alloc, slot(count()));
value_destroy(count(), alloc);
parent()->init_child(position() + 1, dest);
@@ -2334,7 +2352,7 @@ namespace container_internal {
}
// Fixup the counts on the src and dest nodes.
set_count(1 + count() + src->count());
set_count((field_type)(1 + count() + src->count()));
src->set_count(0);
// Remove the value on the parent node.
@@ -4019,4 +4037,9 @@ namespace container_internal {
} // namespace btree
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif // PHMAP_BTREE_BTREE_CONTAINER_H_