llvm.org GIT mirror llvm / 2547e7f
Fixes the Hashing tests on MSVC by adding llvm:: prefix to hash_value function call. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@151971 91177308-0d34-0410-b5e6-96231b3b80d8 Francois Pichet 8 years ago
1 changed file(s) with 25 addition(s) and 29 deletion(s). Raw diff Collapse all Expand all
4141
4242 namespace {
4343
44 #if _MSC_VER != 1600
4544 struct NonPOD {
4645 uint64_t x, y;
4746 NonPOD(uint64_t x, uint64_t y) : x(x), y(y) {}
5049 return hash_combine(obj.x, obj.y);
5150 }
5251 };
53 #endif
5452
5553
5654 TEST(HashingTest, HashValueBasicTest) {
6159 volatile int vi = 71;
6260 const volatile int cvi = 71;
6361 uintptr_t addr = reinterpret_cast(&y);
64 EXPECT_EQ(hash_value(42), hash_value(x));
65 EXPECT_NE(hash_value(42), hash_value(y));
66 EXPECT_NE(hash_value(42), hash_value(p));
67 EXPECT_EQ(hash_value(71), hash_value(i));
68 EXPECT_EQ(hash_value(71), hash_value(ci));
69 EXPECT_EQ(hash_value(71), hash_value(vi));
70 EXPECT_EQ(hash_value(71), hash_value(cvi));
71 EXPECT_EQ(hash_value(c), hash_value('x'));
72 EXPECT_EQ(hash_value('4'), hash_value('0' + 4));
73 EXPECT_EQ(hash_value(addr), hash_value(&y));
74
75 EXPECT_EQ(hash_combine(42, 43), hash_value(std::make_pair(42, 43)));
76 EXPECT_NE(hash_combine(43, 42), hash_value(std::make_pair(42, 43)));
77 EXPECT_NE(hash_combine(42, 43), hash_value(std::make_pair(42ull, 43ull)));
78 EXPECT_NE(hash_combine(42, 43), hash_value(std::make_pair(42, 43ull)));
79 EXPECT_NE(hash_combine(42, 43), hash_value(std::make_pair(42ull, 43)));
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)));
8078
8179 // Note that pairs are implicitly flattened to a direct sequence of data and
8280 // hashed efficiently as a consequence.
83 EXPECT_EQ(hash_combine(42, 43, 44),
84 hash_value(std::make_pair(42, std::make_pair(43, 44))));
85 EXPECT_EQ(hash_value(std::make_pair(42, std::make_pair(43, 44))),
86 hash_value(std::make_pair(std::make_pair(42, 43), 44)));
87
88 #if _MSC_VER != 1600
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)));
85
8986 // Ensure that pairs which have padding bytes *inside* them don't get treated
9087 // this way.
91 EXPECT_EQ(hash_combine('0', hash_combine(1ull, '2')),
92 hash_value(std::make_pair('0', std::make_pair(1ull, '2'))));
88 EXPECT_EQ(llvm::hash_combine('0', hash_combine(1ull, '2')),
89 llvm::hash_value(std::make_pair('0', std::make_pair(1ull, '2'))));
9390
9491 // Ensure that non-POD pairs don't explode the traits used.
9592 NonPOD obj1(1, 2), obj2(3, 4), obj3(5, 6);
96 EXPECT_EQ(hash_combine(obj1, hash_combine(obj2, obj3)),
97 hash_value(std::make_pair(obj1, std::make_pair(obj2, obj3))));
98 #endif
93 EXPECT_EQ(llvm::hash_combine(obj1, hash_combine(obj2, obj3)),
94 llvm::hash_value(std::make_pair(obj1, std::make_pair(obj2, obj3))));
9995 }
10096
10197 template T *begin(T (&arr)[N]) { return arr; }