diff --git a/include/llvm/ADT/StringRef.h b/include/llvm/ADT/StringRef.h index 54330560390..acfc335b805 100644 --- a/include/llvm/ADT/StringRef.h +++ b/include/llvm/ADT/StringRef.h @@ -177,7 +177,7 @@ namespace llvm { size_t Count = 0; for (size_t i = 0, e = Length; i != e; ++i) if (Data[i] == C) - return i; + ++Count; return Count; } diff --git a/unittests/ADT/StringRefTest.cpp b/unittests/ADT/StringRefTest.cpp index ef89e9f3f9d..320633aca8a 100644 --- a/unittests/ADT/StringRefTest.cpp +++ b/unittests/ADT/StringRefTest.cpp @@ -96,6 +96,7 @@ TEST(StringRefTest, Utilities) { EXPECT_TRUE(Str.find("zz") == StringRef::npos); EXPECT_TRUE(Str.count('l') == 2); + EXPECT_TRUE(Str.count('o') == 1); EXPECT_TRUE(Str.count('z') == 0); EXPECT_TRUE(Str.count("helloworld") == 0); EXPECT_TRUE(Str.count("hello") == 1);