Disallow using a hash function whose return type is smaller than size_t. Swisstable relies on the hash having good entropy in both the high and low bits. PiperOrigin-RevId: 786854836 Change-Id: I6fc7041534984a0e937a11f50a2b478390a1a509
diff --git a/absl/container/internal/raw_hash_set.h b/absl/container/internal/raw_hash_set.h index 5fe3367..679d68c 100644 --- a/absl/container/internal/raw_hash_set.h +++ b/absl/container/internal/raw_hash_set.h
@@ -1915,6 +1915,13 @@ auto KeyTypeCanBeHashed(const Hash& h, const key_type& k) -> decltype(h(k)); auto KeyTypeCanBeEq(const Eq& eq, const key_type& k) -> decltype(eq(k, k)); + // Try to be helpful when the hasher returns an unreasonable type. + using key_hash_result = + absl::remove_cvref_t<decltype(std::declval<const Hash&>()( + std::declval<const key_type&>()))>; + static_assert(sizeof(key_hash_result) >= sizeof(size_t), + "`Hash::operator()` should return a `size_t`"); + using AllocTraits = absl::allocator_traits<allocator_type>; using SlotAlloc = typename absl::allocator_traits< allocator_type>::template rebind_alloc<slot_type>;