From f67dadd00a2ac60679375398ffa229b865256425 Mon Sep 17 00:00:00 2001 From: greg7mdp Date: Sun, 25 Jun 2023 14:48:33 -0400 Subject: [PATCH] Fix compilation errors with gcc 4.8.5 Thanks to @aengusjiang for the initial PR, which I updated to simplify and fix compilation issues on windows. --- parallel_hashmap/btree.h | 16 ++++++------ parallel_hashmap/phmap_base.h | 43 ++++++++++++++++++++++++++++++--- parallel_hashmap/phmap_config.h | 10 +++++--- 3 files changed, 54 insertions(+), 15 deletions(-) diff --git a/parallel_hashmap/btree.h b/parallel_hashmap/btree.h index 0cafd18..bf4d96a 100644 --- a/parallel_hashmap/btree.h +++ b/parallel_hashmap/btree.h @@ -108,7 +108,7 @@ namespace phmap { bool, std::is_copy_constructible< type_traits_internal::SingleMemberUnion>::value && std::is_trivially_destructible::value> {}; - +#if 0 template struct IsTriviallyMoveAssignableReference : std::false_type {}; @@ -119,7 +119,7 @@ namespace phmap { template struct IsTriviallyMoveAssignableReference : std::is_trivially_move_assignable::type {}; - +#endif } // namespace type_traits_internal @@ -148,8 +148,8 @@ namespace phmap { public: static constexpr bool kValue = - (std::is_trivially_copyable::value || !kIsCopyOrMoveConstructible) && - (std::is_trivially_copy_assignable::value || !kIsCopyOrMoveAssignable) && + (phmap::is_trivially_copyable::value || !kIsCopyOrMoveConstructible) && + (phmap::is_trivially_copy_assignable::value || !kIsCopyOrMoveAssignable) && (kIsCopyOrMoveConstructible || kIsCopyOrMoveAssignable) && std::is_trivially_destructible::value && // We need to check for this explicitly because otherwise we'll say @@ -3321,8 +3321,8 @@ namespace priv { // ---------------- template size_type count(const key_arg &key) const { - auto equal_range = this->equal_range(key); - return std::distance(equal_range.first, equal_range.second); + auto er = this->equal_range(key); + return std::distance(er.first, er.second); } template iterator find(const key_arg &key) { @@ -3362,8 +3362,8 @@ namespace priv { } template size_type erase(const key_arg &key) { - auto equal_range = this->equal_range(key); - return tree_.erase_range(equal_range.first, equal_range.second).first; + auto er = this->equal_range(key); + return tree_.erase_range(er.first, er.second).first; } node_type extract(iterator position) { // Use Move instead of Transfer, because the rebalancing code expects to diff --git a/parallel_hashmap/phmap_base.h b/parallel_hashmap/phmap_base.h index 265508c..3483d5b 100644 --- a/parallel_hashmap/phmap_base.h +++ b/parallel_hashmap/phmap_base.h @@ -223,6 +223,36 @@ struct disjunction<> : std::false_type {}; template struct negation : std::integral_constant {}; +#if defined(__GNUC__) && __GNUC__ < 5 && !defined(__clang__) && !defined(_MSC_VER) && !defined(__INTEL_COMPILER) + #define PHMAP_OLD_GCC 1 +#else + #define PHMAP_OLD_GCC 0 +#endif + +#if PHMAP_OLD_GCC + template + struct is_trivially_copy_constructible + : std::integral_constant::type) && + std::is_copy_constructible::value && + std::is_trivially_destructible::value> {}; + + template + struct is_trivially_copy_assignable : + std::integral_constant::type) && + phmap::is_copy_assignable::value> {}; + + template + struct is_trivially_copyable : + std::integral_constant::type)> {}; + +#else + template using is_trivially_copy_constructible = std::is_trivially_copy_constructible; + template using is_trivially_copy_assignable = std::is_trivially_copy_assignable; + template using is_trivially_copyable = std::is_trivially_copyable; +#endif + // ----------------------------------------------------------------------------- // C++14 "_t" trait aliases // ----------------------------------------------------------------------------- @@ -1788,8 +1818,8 @@ protected: // supported now, so we use is_trivially_* traits instead. template ::value && - std::is_trivially_copy_assignable::type>::value && + phmap::is_trivially_copy_constructible::value && + phmap::is_trivially_copy_assignable::type>::value && std::is_trivially_destructible::value> class optional_data; @@ -2021,6 +2051,11 @@ struct optional_hash_base >()( // ----------------------------------------------------------------------------- // phmap::optional class definition // ----------------------------------------------------------------------------- +#if PHMAP_OLD_GCC + #define PHMAP_OPTIONAL_NOEXCEPT +#else + #define PHMAP_OPTIONAL_NOEXCEPT noexcept +#endif template class optional : private optional_internal::optional_data, @@ -2047,7 +2082,7 @@ public: optional(const optional& src) = default; // Move constructor, standard semantics - optional(optional&& src) noexcept = default; + optional(optional&& src) PHMAP_OPTIONAL_NOEXCEPT = default; // Constructs a non-empty `optional` direct-initialized value of type `T` from // the arguments `std::forward(args)...` within the `optional`. @@ -2187,7 +2222,7 @@ public: optional& operator=(const optional& src) = default; // Move assignment operator, standard semantics - optional& operator=(optional&& src) noexcept = default; + optional& operator=(optional&& src) PHMAP_OPTIONAL_NOEXCEPT = default; // Value assignment operators template < diff --git a/parallel_hashmap/phmap_config.h b/parallel_hashmap/phmap_config.h index 88edaae..8a881f4 100644 --- a/parallel_hashmap/phmap_config.h +++ b/parallel_hashmap/phmap_config.h @@ -120,7 +120,7 @@ #define PHMAP_HAVE_BUILTIN(x) 0 #endif -#if (defined(_MSVC_LANG) && _MSVC_LANG >= 201703) || __cplusplus >= 201703 +#if (!defined(__GNUC__) || __GNUC__ >= 5) && ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L) #define PHMAP_HAVE_CC17 1 #else #define PHMAP_HAVE_CC17 0 @@ -313,8 +313,12 @@ #endif #endif -#if PHMAP_HAVE_CC17 && (!defined(__has_include) || __has_include()) - #define PHMAP_HAVE_SHARED_MUTEX 1 +#if PHMAP_HAVE_CC17 + #ifdef __has_include + #if __has_include() + #define PHMAP_HAVE_SHARED_MUTEX 1 + #endif + #endif #endif #ifndef PHMAP_HAVE_STD_STRING_VIEW