summaryrefslogtreecommitdiff
path: root/absl
diff options
context:
space:
mode:
Diffstat (limited to 'absl')
-rw-r--r--absl/hash/hash_test.cc15
-rw-r--r--absl/hash/internal/hash.h3
2 files changed, 15 insertions, 3 deletions
diff --git a/absl/hash/hash_test.cc b/absl/hash/hash_test.cc
index 5b556180..4ed6e50a 100644
--- a/absl/hash/hash_test.cc
+++ b/absl/hash/hash_test.cc
@@ -17,6 +17,7 @@
#include <algorithm>
#include <array>
#include <bitset>
+#include <cstdint>
#include <cstring>
#include <deque>
#include <forward_list>
@@ -1241,14 +1242,24 @@ TEST(HashTest, DoesNotUseImplicitConversionsToBool) {
TEST(HashOf, MatchesHashForSingleArgument) {
std::string s = "forty two";
- int i = 42;
double d = 42.0;
std::tuple<int, int> t{4, 2};
+ int i = 42;
+ int neg_i = -42;
+ int16_t i16 = 42;
+ int16_t neg_i16 = -42;
+ int8_t i8 = 42;
+ int8_t neg_i8 = -42;
EXPECT_EQ(absl::HashOf(s), absl::Hash<std::string>{}(s));
- EXPECT_EQ(absl::HashOf(i), absl::Hash<int>{}(i));
EXPECT_EQ(absl::HashOf(d), absl::Hash<double>{}(d));
EXPECT_EQ(absl::HashOf(t), (absl::Hash<std::tuple<int, int>>{}(t)));
+ EXPECT_EQ(absl::HashOf(i), absl::Hash<int>{}(i));
+ EXPECT_EQ(absl::HashOf(neg_i), absl::Hash<int>{}(neg_i));
+ EXPECT_EQ(absl::HashOf(i16), absl::Hash<int16_t>{}(i16));
+ EXPECT_EQ(absl::HashOf(neg_i16), absl::Hash<int16_t>{}(neg_i16));
+ EXPECT_EQ(absl::HashOf(i8), absl::Hash<int8_t>{}(i8));
+ EXPECT_EQ(absl::HashOf(neg_i8), absl::Hash<int8_t>{}(neg_i8));
}
TEST(HashOf, MatchesHashOfTupleForMultipleArguments) {
diff --git a/absl/hash/internal/hash.h b/absl/hash/internal/hash.h
index ccf4cc1a..eb50e2c7 100644
--- a/absl/hash/internal/hash.h
+++ b/absl/hash/internal/hash.h
@@ -969,7 +969,8 @@ class ABSL_DLL MixingHashState : public HashStateBase<MixingHashState> {
// The result should be the same as running the whole algorithm, but faster.
template <typename T, absl::enable_if_t<IntegralFastPath<T>::value, int> = 0>
static size_t hash(T value) {
- return static_cast<size_t>(Mix(Seed(), static_cast<uint64_t>(value)));
+ return static_cast<size_t>(
+ Mix(Seed(), static_cast<std::make_unsigned_t<T>>(value)));
}
// Overload of MixingHashState::hash()