Index: include/llvm/ADT/DenseSet.h =================================================================== --- include/llvm/ADT/DenseSet.h +++ include/llvm/ADT/DenseSet.h @@ -135,6 +135,7 @@ const_iterator end() const { return ConstIterator(TheMap.end()); } iterator find(const ValueT &V) { return Iterator(TheMap.find(V)); } + const_iterator find(const ValueT &V) const { return ConstIterator(TheMap.find(V)); } /// Alternative version of find() which allows a different, and possibly less /// expensive, key type. Index: unittests/ADT/DenseSetTest.cpp =================================================================== --- unittests/ADT/DenseSetTest.cpp +++ unittests/ADT/DenseSetTest.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +#include #include "gtest/gtest.h" #include "llvm/ADT/DenseSet.h" @@ -14,12 +15,8 @@ namespace { -// Test fixture -class DenseSetTest : public testing::Test { -}; - // Test hashing with a set of only two entries. -TEST_F(DenseSetTest, DoubleEntrySetTest) { +TEST(DenseSetTest, DoubleEntrySetTest) { llvm::DenseSet set(2); set.insert(0); set.insert(1); @@ -42,12 +39,30 @@ } }; -TEST(DenseSetCustomTest, FindAsTest) { - DenseSet set; - set.insert(0); - set.insert(1); - set.insert(2); +// Test fixture +template +class DenseSetTest : public testing::Test { + protected: + T Set = GetTestSet(); + + private: + static T GetTestSet() { + typename std::remove_const::type Set; + Set.insert(0); + Set.insert(1); + Set.insert(2); + return Set; + } +}; + +// Register these types for testing. +typedef ::testing::Types, + const DenseSet + > DenseSetTestTypes; +TYPED_TEST_CASE(DenseSetTest, DenseSetTestTypes); +TYPED_TEST(DenseSetTest, FindAsTest) { + auto& set = this->Set; // Size tests EXPECT_EQ(3u, set.size());