cleanup more warnings with MSVC

This commit is contained in:
greg
2019-12-31 13:26:03 -05:00
parent 1d5651cffe
commit fd2f93683c
4 changed files with 78 additions and 164 deletions
+31 -23
View File
@@ -57,8 +57,16 @@
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(push) #pragma warning(push)
// warning C4820: '6' bytes padding added after data member
#pragma warning(disable : 4820) #pragma warning(disable : 4127) // conditional expression is constant
#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 : 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 : 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 #endif
namespace phmap { namespace phmap {
@@ -283,6 +291,11 @@ inline bool IsEmptyOrDeleted(ctrl_t c) { return c < kSentinel; }
#if PHMAP_HAVE_SSE2 #if PHMAP_HAVE_SSE2
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4365) // conversion from 'int' to 'T', signed/unsigned mismatch
#endif
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// https://github.com/abseil/abseil-cpp/issues/209 // https://github.com/abseil/abseil-cpp/issues/209
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87853 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87853
@@ -368,6 +381,11 @@ struct GroupSse2Impl
__m128i ctrl; __m128i ctrl;
}; };
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif // PHMAP_HAVE_SSE2 #endif // PHMAP_HAVE_SSE2
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@@ -467,12 +485,6 @@ inline size_t NormalizeCapacity(size_t n)
return n ? ~size_t{} >> LeadingZeros(n) : 1; return n ? ~size_t{} >> LeadingZeros(n) : 1;
} }
#ifdef _MSC_VER
#pragma warning(push)
// warning C4127: conditional expression is constant
#pragma warning(disable : 4127)
#endif
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// We use 7/8th as maximum load factor. // We use 7/8th as maximum load factor.
// For 16-wide groups, that gives an average of two empty slots per group. // For 16-wide groups, that gives an average of two empty slots per group.
@@ -502,10 +514,6 @@ inline size_t GrowthToLowerboundCapacity(size_t growth)
return growth + static_cast<size_t>((static_cast<int64_t>(growth) - 1) / 7); return growth + static_cast<size_t>((static_cast<int64_t>(growth) - 1) / 7);
} }
#ifdef _MSC_VER
#pragma warning(pop)
#endif
namespace hashtable_debug_internal { namespace hashtable_debug_internal {
// If it is a map, call get<0>(). // If it is a map, call get<0>().
@@ -1550,11 +1558,11 @@ public:
auto seq = probe(hash); auto seq = probe(hash);
while (true) { while (true) {
Group g{ctrl_ + seq.offset()}; Group g{ctrl_ + seq.offset()};
for (int i : g.Match(H2(hash))) { for (int i : g.Match((h2_t)H2(hash))) {
if (PHMAP_PREDICT_TRUE(PolicyTraits::apply( if (PHMAP_PREDICT_TRUE(PolicyTraits::apply(
EqualElement<K>{key, eq_ref()}, EqualElement<K>{key, eq_ref()},
PolicyTraits::element(slots_ + seq.offset(i))))) PolicyTraits::element(slots_ + seq.offset((size_t)i)))))
return iterator_at(seq.offset(i)); return iterator_at(seq.offset((size_t)i));
} }
if (PHMAP_PREDICT_TRUE(g.MatchEmpty())) if (PHMAP_PREDICT_TRUE(g.MatchEmpty()))
return end(); return end();
@@ -1725,7 +1733,7 @@ private:
void erase_meta_only(const_iterator it) { void erase_meta_only(const_iterator it) {
assert(IsFull(*it.inner_.ctrl_) && "erasing a dangling iterator"); assert(IsFull(*it.inner_.ctrl_) && "erasing a dangling iterator");
--size_; --size_;
const size_t index = it.inner_.ctrl_ - ctrl_; const size_t index = (size_t)(it.inner_.ctrl_ - ctrl_);
const size_t index_before = (index - Group::kWidth) & capacity_; const size_t index_before = (index - Group::kWidth) & capacity_;
const auto empty_after = Group(it.inner_.ctrl_).MatchEmpty(); const auto empty_after = Group(it.inner_.ctrl_).MatchEmpty();
const auto empty_before = Group(ctrl_ + index_before).MatchEmpty(); const auto empty_before = Group(ctrl_ + index_before).MatchEmpty();
@@ -1884,8 +1892,8 @@ private:
auto seq = probe(hash); auto seq = probe(hash);
while (true) { while (true) {
Group g{ctrl_ + seq.offset()}; Group g{ctrl_ + seq.offset()};
for (int i : g.Match(H2(hash))) { for (int i : g.Match((h2_t)H2(hash))) {
if (PHMAP_PREDICT_TRUE(PolicyTraits::element(slots_ + seq.offset(i)) == if (PHMAP_PREDICT_TRUE(PolicyTraits::element(slots_ + seq.offset((size_t)i)) ==
elem)) elem))
return true; return true;
} }
@@ -1921,7 +1929,7 @@ private:
Group g{ctrl_ + seq.offset()}; Group g{ctrl_ + seq.offset()};
auto mask = g.MatchEmptyOrDeleted(); auto mask = g.MatchEmptyOrDeleted();
if (mask) { if (mask) {
return {seq.offset(mask.LowestBitSet()), seq.index()}; return {seq.offset((size_t)mask.LowestBitSet()), seq.index()};
} }
assert(seq.index() < capacity_ && "full table!"); assert(seq.index() < capacity_ && "full table!");
seq.next(); seq.next();
@@ -1946,11 +1954,11 @@ protected:
auto seq = probe(hash); auto seq = probe(hash);
while (true) { while (true) {
Group g{ctrl_ + seq.offset()}; Group g{ctrl_ + seq.offset()};
for (int i : g.Match(H2(hash))) { for (int i : g.Match((h2_t)H2(hash))) {
if (PHMAP_PREDICT_TRUE(PolicyTraits::apply( if (PHMAP_PREDICT_TRUE(PolicyTraits::apply(
EqualElement<K>{key, eq_ref()}, EqualElement<K>{key, eq_ref()},
PolicyTraits::element(slots_ + seq.offset(i))))) PolicyTraits::element(slots_ + seq.offset((size_t)i)))))
return {seq.offset(i), false}; return {seq.offset((size_t)i), false};
} }
if (PHMAP_PREDICT_TRUE(g.MatchEmpty())) break; if (PHMAP_PREDICT_TRUE(g.MatchEmpty())) break;
seq.next(); seq.next();
@@ -3844,7 +3852,7 @@ struct HashtableDebugAccess<Set, phmap::void_t<typename Set::raw_hash_set>>
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()},
Traits::element(set.slots_ + seq.offset(i)))) Traits::element(set.slots_ + seq.offset((size_t)i))))
return num_probes; return num_probes;
++num_probes; ++num_probes;
} }
+30 -141
View File
@@ -54,6 +54,15 @@
#include <shared_mutex> // after "phmap_config.h" #include <shared_mutex> // after "phmap_config.h"
#endif #endif
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4514) // unreferenced inline function has been removed
#pragma warning(disable : 4582) // constructor is not implicitly called
#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 : 4820) // '6' bytes padding added after data member
#endif // _MSC_VER
namespace phmap { namespace phmap {
template <class T> using Allocator = typename std::allocator<T>; template <class T> using Allocator = typename std::allocator<T>;
@@ -213,166 +222,31 @@ struct disjunction<T> : T {};
template <> template <>
struct disjunction<> : std::false_type {}; struct disjunction<> : std::false_type {};
// ---------------------------------------------------------------------------
// negation
//
// Performs a compile-time logical NOT operation on the passed type (which
// must have `::value` members convertible to `bool`.
//
// This metafunction is designed to be a drop-in replacement for the C++17
// `std::negation` metafunction.
// ---------------------------------------------------------------------------
template <typename T> template <typename T>
struct negation : std::integral_constant<bool, !T::value> {}; struct negation : std::integral_constant<bool, !T::value> {};
// ---------------------------------------------------------------------------
// is_trivially_destructible()
//
// Determines whether the passed type `T` is trivially destructable.
//
// This metafunction is designed to be a drop-in replacement for the C++11
// `std::is_trivially_destructible()` metafunction for platforms that have
// incomplete C++11 support (such as libstdc++ 4.x). On any platforms that do
// fully support C++11, we check whether this yields the same result as the std
// implementation.
//
// NOTE: the extensions (__has_trivial_xxx) are implemented in gcc (version >=
// 4.3) and clang. Since we are supporting libstdc++ > 4.7, they should always
// be present. These extensions are documented at
// https://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html#Type-Traits.
// ---------------------------------------------------------------------------
template <typename T> template <typename T>
struct is_trivially_destructible struct is_trivially_destructible
: std::integral_constant<bool, __has_trivial_destructor(T) && : std::integral_constant<bool, __has_trivial_destructor(T) &&
std::is_destructible<T>::value> std::is_destructible<T>::value> {};
{
};
// ---------------------------------------------------------------------------
// is_trivially_default_constructible()
//
// Determines whether the passed type `T` is trivially default constructible.
//
// This metafunction is designed to be a drop-in replacement for the C++11
// `std::is_trivially_default_constructible()` metafunction for platforms that
// have incomplete C++11 support (such as libstdc++ 4.x). On any platforms that
// do fully support C++11, we check whether this yields the same result as the
// std implementation.
//
// NOTE: according to the C++ standard, Section: 20.15.4.3 [meta.unary.prop]
// "The predicate condition for a template specialization is_constructible<T,
// Args...> shall be satisfied if and only if the following variable
// definition would be well-formed for some invented variable t:
//
// T t(declval<Args>()...);
//
// is_trivially_constructible<T, Args...> additionally requires that the
// variable definition does not call any operation that is not trivial.
// For the purposes of this check, the call to std::declval is considered
// trivial."
//
// Notes from https://en.cppreference.com/w/cpp/types/is_constructible:
// In many implementations, is_nothrow_constructible also checks if the
// destructor throws because it is effectively noexcept(T(arg)). Same
// applies to is_trivially_constructible, which, in these implementations, also
// requires that the destructor is trivial.
// GCC bug 51452: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51452
// LWG issue 2116: http://cplusplus.github.io/LWG/lwg-active.html#2116.
//
// "T obj();" need to be well-formed and not call any nontrivial operation.
// Nontrivially destructible types will cause the expression to be nontrivial.
// ---------------------------------------------------------------------------
template <typename T> template <typename T>
struct is_trivially_default_constructible struct is_trivially_default_constructible
: std::integral_constant<bool, __has_trivial_constructor(T) && : std::integral_constant<bool, __has_trivial_constructor(T) &&
std::is_default_constructible<T>::value && std::is_default_constructible<T>::value &&
is_trivially_destructible<T>::value> is_trivially_destructible<T>::value> {};
{
#ifdef PHMAP_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE
private:
static constexpr bool compliant =
std::is_trivially_default_constructible<T>::value ==
is_trivially_default_constructible::value;
static_assert(compliant || std::is_trivially_default_constructible<T>::value,
"Not compliant with std::is_trivially_default_constructible; "
"Standard: false, Implementation: true");
static_assert(compliant || !std::is_trivially_default_constructible<T>::value,
"Not compliant with std::is_trivially_default_constructible; "
"Standard: true, Implementation: false");
#endif
};
// ---------------------------------------------------------------------------
// is_trivially_copy_constructible()
//
// Determines whether the passed type `T` is trivially copy constructible.
//
// This metafunction is designed to be a drop-in replacement for the C++11
// `std::is_trivially_copy_constructible()` metafunction for platforms that have
// incomplete C++11 support (such as libstdc++ 4.x). On any platforms that do
// fully support C++11, we check whether this yields the same result as the std
// implementation.
//
// NOTE: `T obj(declval<const T&>());` needs to be well-formed and not call any
// nontrivial operation. Nontrivially destructible types will cause the
// expression to be nontrivial.
// ---------------------------------------------------------------------------
template <typename T> template <typename T>
struct is_trivially_copy_constructible struct is_trivially_copy_constructible
: std::integral_constant<bool, __has_trivial_copy(T) && : std::integral_constant<bool, __has_trivial_copy(T) &&
std::is_copy_constructible<T>::value && std::is_copy_constructible<T>::value &&
is_trivially_destructible<T>::value> is_trivially_destructible<T>::value> {};
{
#ifdef PHMAP_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE
private:
static constexpr bool compliant =
std::is_trivially_copy_constructible<T>::value ==
is_trivially_copy_constructible::value;
static_assert(compliant || std::is_trivially_copy_constructible<T>::value,
"Not compliant with std::is_trivially_copy_constructible; "
"Standard: false, Implementation: true");
static_assert(compliant || !std::is_trivially_copy_constructible<T>::value,
"Not compliant with std::is_trivially_copy_constructible; "
"Standard: true, Implementation: false");
#endif
};
// ---------------------------------------------------------------------------
// is_trivially_copy_assignable()
//
// Determines whether the passed type `T` is trivially copy assignable.
//
// This metafunction is designed to be a drop-in replacement for the C++11
// `std::is_trivially_copy_assignable()` metafunction for platforms that have
// incomplete C++11 support (such as libstdc++ 4.x). On any platforms that do
// fully support C++11, we check whether this yields the same result as the std
// implementation.
//
// NOTE: `is_assignable<T, U>::value` is `true` if the expression
// `declval<T>() = declval<U>()` is well-formed when treated as an unevaluated
// operand. `is_trivially_assignable<T, U>` requires the assignment to call no
// operation that is not trivial. `is_trivially_copy_assignable<T>` is simply
// `is_trivially_assignable<T&, const T&>`.
// ---------------------------------------------------------------------------
template <typename T> template <typename T>
struct is_trivially_copy_assignable struct is_trivially_copy_assignable
: std::integral_constant< : std::integral_constant<
bool, __has_trivial_assign(typename std::remove_reference<T>::type) && bool, __has_trivial_assign(typename std::remove_reference<T>::type) &&
phmap::is_copy_assignable<T>::value> phmap::is_copy_assignable<T>::value> {};
{
#ifdef PHMAP_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE
private:
static constexpr bool compliant =
std::is_trivially_copy_assignable<T>::value ==
is_trivially_copy_assignable::value;
static_assert(compliant || std::is_trivially_copy_assignable<T>::value,
"Not compliant with std::is_trivially_copy_assignable; "
"Standard: false, Implementation: true");
static_assert(compliant || !std::is_trivially_copy_assignable<T>::value,
"Not compliant with std::is_trivially_copy_assignable; "
"Standard: true, Implementation: false");
#endif
};
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// C++14 "_t" trait aliases // C++14 "_t" trait aliases
@@ -1216,6 +1090,11 @@ auto apply(Functor&& functor, Tuple&& t)
typename std::remove_reference<Tuple>::type>::value>{}); typename std::remove_reference<Tuple>::type>::value>{});
} }
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4365) // '=': conversion from 'T' to 'T', signed/unsigned mismatch
#endif // _MSC_VER
// exchange // exchange
// //
// Replaces the value of `obj` with `new_value` and returns the old value of // Replaces the value of `obj` with `new_value` and returns the old value of
@@ -1237,6 +1116,11 @@ T exchange(T& obj, U&& new_value)
return old_value; return old_value;
} }
#ifdef _MSC_VER
#pragma warning(pop)
#endif // _MSC_VER
} // namespace phmap } // namespace phmap
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@@ -2895,8 +2779,8 @@ protected:
PolicyTraits::transfer(alloc(), slot(), s); PolicyTraits::transfer(alloc(), slot(), s);
} }
node_handle_base(const node_handle_base&) = delete; //node_handle_base(const node_handle_base&) = delete;
node_handle_base& operator=(const node_handle_base&) = delete; //node_handle_base& operator=(const node_handle_base&) = delete;
void destroy() { void destroy() {
if (!empty()) { if (!empty()) {
@@ -5264,4 +5148,9 @@ public:
} // phmap } // phmap
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif // phmap_base_h_guard_ #endif // phmap_base_h_guard_
+9
View File
@@ -50,6 +50,11 @@
#include <cstdint> #include <cstdint>
#include "phmap_config.h" #include "phmap_config.h"
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4514) // unreferenced inline function has been removed
#endif
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// unaligned APIs // unaligned APIs
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@@ -651,4 +656,8 @@ inline void Store64(void *p, uint64_t v) {
} // namespace phmap } // namespace phmap
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif // phmap_bits_h_guard_ #endif // phmap_bits_h_guard_
+8
View File
@@ -26,6 +26,11 @@
#include <tuple> #include <tuple>
#include "phmap_bits.h" #include "phmap_bits.h"
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4514) // unreferenced inline function has been removed
#endif
namespace phmap namespace phmap
{ {
@@ -356,5 +361,8 @@ private:
} // namespace phmap } // namespace phmap
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif // phmap_utils_h_guard_ #endif // phmap_utils_h_guard_