diff options
author | Daniel Berlin <dberlin@dberlin.org> | 2017-03-10 00:25:26 +0000 |
---|---|---|
committer | Daniel Berlin <dberlin@dberlin.org> | 2017-03-10 00:25:26 +0000 |
commit | 04d9e746f1792ecf610d823eb486332e1ab8030b (patch) | |
tree | cb97ed235609f8ffd39f5eda7a00d876f92f8e61 /llvm/unittests/ADT/DenseMapTest.cpp | |
parent | e42462da35a963053d1d9ad096234d3ddb35cf11 (diff) | |
download | llvm-04d9e746f1792ecf610d823eb486332e1ab8030b.zip llvm-04d9e746f1792ecf610d823eb486332e1ab8030b.tar.gz llvm-04d9e746f1792ecf610d823eb486332e1ab8030b.tar.bz2 |
Add support for DenseMap/DenseSet count and find using const pointers
Summary:
Similar to SmallPtrSet, this makes find and count work with both const
referneces and const pointers.
Reviewers: dblaikie
Subscribers: llvm-commits, mzolotukhin
Differential Revision: https://reviews.llvm.org/D30713
llvm-svn: 297424
Diffstat (limited to 'llvm/unittests/ADT/DenseMapTest.cpp')
-rw-r--r-- | llvm/unittests/ADT/DenseMapTest.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/DenseMapTest.cpp b/llvm/unittests/ADT/DenseMapTest.cpp index 80f0462..273f4da 100644 --- a/llvm/unittests/ADT/DenseMapTest.cpp +++ b/llvm/unittests/ADT/DenseMapTest.cpp @@ -580,4 +580,18 @@ TEST(DenseMapCustomTest, TryEmplaceTest) { EXPECT_EQ(Try1.first, Try2.first); EXPECT_NE(nullptr, P); } + +TEST(DenseMapCustomTest, ConstTest) { + // Test that const pointers work okay for count and find, even when the + // underlying map is a non-const pointer. + DenseMap<int *, int> Map; + int A; + int *B = &A; + const int *C = &A; + Map.insert({B, 0}); + EXPECT_EQ(Map.count(B), 1u); + EXPECT_EQ(Map.count(C), 1u); + EXPECT_NE(Map.find(B), Map.end()); + EXPECT_NE(Map.find(C), Map.end()); +} } |