diff --git a/include/llvm/ADT/StringMap.h b/include/llvm/ADT/StringMap.h index 95c973bcc9a..35077879351 100644 --- a/include/llvm/ADT/StringMap.h +++ b/include/llvm/ADT/StringMap.h @@ -140,7 +140,7 @@ public: /// StringMapEntry object. const char *getKeyData() const {return reinterpret_cast(this+1);} - const char *first() const { return getKeyData(); } + StringRef first() const { return StringRef(getKeyData(), getKeyLength()); } /// Create - Create a StringMapEntry for the specified key and default /// construct the value. diff --git a/unittests/ADT/StringMapTest.cpp b/unittests/ADT/StringMapTest.cpp index ea91348a5bd..2ae58204e18 100644 --- a/unittests/ADT/StringMapTest.cpp +++ b/unittests/ADT/StringMapTest.cpp @@ -51,7 +51,7 @@ protected: // Iterator tests StringMap::iterator it = testMap.begin(); - EXPECT_STREQ(testKey, it->first()); + EXPECT_STREQ(testKey, it->first().data()); EXPECT_EQ(testValue, it->second); ++it; EXPECT_TRUE(it == testMap.end()); @@ -157,7 +157,7 @@ TEST_F(StringMapTest, IterationTest) { it != testMap.end(); ++it) { std::stringstream ss; ss << "key_" << it->second; - ASSERT_STREQ(ss.str().c_str(), it->first()); + ASSERT_STREQ(ss.str().c_str(), it->first().data()); visited[it->second] = true; } @@ -189,7 +189,7 @@ TEST_F(StringMapTest, StringMapEntryTest) { StringMap::value_type* entry = StringMap::value_type::Create( testKeyFirst, testKeyFirst + testKeyLength, 1u); - EXPECT_STREQ(testKey, entry->first()); + EXPECT_STREQ(testKey, entry->first().data()); EXPECT_EQ(1u, entry->second); free(entry); }