llvm.org GIT mirror llvm / 5fa6f5b
Move the NonPOD struct out of the anonymous namespace instead of adding llvm:: everywhere to fix the HashingTest on MSVC . chandlerc proposed this better solution on IRC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@151974 91177308-0d34-0410-b5e6-96231b3b80d8 Francois Pichet 8 years ago
1 changed file(s) with 36 addition(s) and 36 deletion(s). Raw diff Collapse all Expand all
2929 // objects.
3030 struct LargeTestInteger { uint64_t arr[8]; };
3131
32 namespace hashing {
33 namespace detail {
34 template <> struct is_hashable_data : true_type {};
35 } // namespace detail
36 } // namespace hashing
37
38 } // namespace llvm
39
40 using namespace llvm;
41
42 namespace {
43
4432 struct NonPOD {
4533 uint64_t x, y;
4634 NonPOD(uint64_t x, uint64_t y) : x(x), y(y) {}
4937 return hash_combine(obj.x, obj.y);
5038 }
5139 };
40
41 namespace hashing {
42 namespace detail {
43 template <> struct is_hashable_data : true_type {};
44 } // namespace detail
45 } // namespace hashing
46
47 } // namespace llvm
48
49 using namespace llvm;
50
51 namespace {
5252
5353
5454 TEST(HashingTest, HashValueBasicTest) {
5959 volatile int vi = 71;
6060 const volatile int cvi = 71;
6161 uintptr_t addr = reinterpret_cast(&y);
62 EXPECT_EQ(llvm::hash_value(42), llvm::hash_value(x));
63 EXPECT_NE(llvm::hash_value(42), llvm::hash_value(y));
64 EXPECT_NE(llvm::hash_value(42), llvm::hash_value(p));
65 EXPECT_EQ(llvm::hash_value(71), llvm::hash_value(i));
66 EXPECT_EQ(llvm::hash_value(71), llvm::hash_value(ci));
67 EXPECT_EQ(llvm::hash_value(71), llvm::hash_value(vi));
68 EXPECT_EQ(llvm::hash_value(71), llvm::hash_value(cvi));
69 EXPECT_EQ(llvm::hash_value(c), llvm::hash_value('x'));
70 EXPECT_EQ(llvm::hash_value('4'), llvm::hash_value('0' + 4));
71 EXPECT_EQ(llvm::hash_value(addr), llvm::hash_value(&y));
72
73 EXPECT_EQ(llvm::hash_combine(42, 43), llvm::hash_value(std::make_pair(42, 43)));
74 EXPECT_NE(llvm::hash_combine(43, 42), llvm::hash_value(std::make_pair(42, 43)));
75 EXPECT_NE(llvm::hash_combine(42, 43), llvm::hash_value(std::make_pair(42ull, 43ull)));
76 EXPECT_NE(llvm::hash_combine(42, 43), llvm::hash_value(std::make_pair(42, 43ull)));
77 EXPECT_NE(llvm::hash_combine(42, 43), llvm::hash_value(std::make_pair(42ull, 43)));
62 EXPECT_EQ(hash_value(42), hash_value(x));
63 EXPECT_NE(hash_value(42), hash_value(y));
64 EXPECT_NE(hash_value(42), hash_value(p));
65 EXPECT_EQ(hash_value(71), hash_value(i));
66 EXPECT_EQ(hash_value(71), hash_value(ci));
67 EXPECT_EQ(hash_value(71), hash_value(vi));
68 EXPECT_EQ(hash_value(71), hash_value(cvi));
69 EXPECT_EQ(hash_value(c), hash_value('x'));
70 EXPECT_EQ(hash_value('4'), hash_value('0' + 4));
71 EXPECT_EQ(hash_value(addr), hash_value(&y));
72
73 EXPECT_EQ(hash_combine(42, 43), hash_value(std::make_pair(42, 43)));
74 EXPECT_NE(hash_combine(43, 42), hash_value(std::make_pair(42, 43)));
75 EXPECT_NE(hash_combine(42, 43), hash_value(std::make_pair(42ull, 43ull)));
76 EXPECT_NE(hash_combine(42, 43), hash_value(std::make_pair(42, 43ull)));
77 EXPECT_NE(hash_combine(42, 43), hash_value(std::make_pair(42ull, 43)));
7878
7979 // Note that pairs are implicitly flattened to a direct sequence of data and
8080 // hashed efficiently as a consequence.
81 EXPECT_EQ(llvm::hash_combine(42, 43, 44),
82 llvm::hash_value(std::make_pair(42, std::make_pair(43, 44))));
83 EXPECT_EQ(llvm::hash_value(std::make_pair(42, std::make_pair(43, 44))),
84 llvm::hash_value(std::make_pair(std::make_pair(42, 43), 44)));
81 EXPECT_EQ(hash_combine(42, 43, 44),
82 hash_value(std::make_pair(42, std::make_pair(43, 44))));
83 EXPECT_EQ(hash_value(std::make_pair(42, std::make_pair(43, 44))),
84 hash_value(std::make_pair(std::make_pair(42, 43), 44)));
8585
8686 // Ensure that pairs which have padding bytes *inside* them don't get treated
8787 // this way.
88 EXPECT_EQ(llvm::hash_combine('0', hash_combine(1ull, '2')),
89 llvm::hash_value(std::make_pair('0', std::make_pair(1ull, '2'))));
88 EXPECT_EQ(hash_combine('0', hash_combine(1ull, '2')),
89 hash_value(std::make_pair('0', std::make_pair(1ull, '2'))));
9090
9191 // Ensure that non-POD pairs don't explode the traits used.
9292 NonPOD obj1(1, 2), obj2(3, 4), obj3(5, 6);
93 EXPECT_EQ(llvm::hash_combine(obj1, hash_combine(obj2, obj3)),
94 llvm::hash_value(std::make_pair(obj1, std::make_pair(obj2, obj3))));
93 EXPECT_EQ(hash_combine(obj1, hash_combine(obj2, obj3)),
94 hash_value(std::make_pair(obj1, std::make_pair(obj2, obj3))));
9595 }
9696
9797 template T *begin(T (&arr)[N]) { return arr; }