Moving to the appropriate list (cfe-commits) & adding Howard.
---------- Forwarded message ----------
From: Klaas de Vries <[email protected]>
Date: Mon, Dec 31, 2012 at 6:06 AM
Subject: [llvm-commits] bug in libc++'s std::string::find_first_not_of
To: [email protected]
Hi,
It seems that the libc++ implementation of
std::string::find_first_not_of - specifically the one taking a single
character as its first argument - does not handle the case where the
string contains only the given character (i.e. where it should return
string::npos).
A simple program demonstrating this:
int main()
{
string test("--");
string::size_type i = test.find_first_not_of('-');
cout << (i == string::npos ? "okay" : "not okay") << '\n';
}
The cause seems to be a typo in the for-loop in the implementation
where a check for the inequality will return true for the first
character beyond the tested string (a bad thing).
Attached is what I believe to be a fix, and an updated test case.
Regards,
Klaas de Vries
_______________________________________________
llvm-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
Index: include/string
===================================================================
--- include/string (revision 171297)
+++ include/string (working copy)
@@ -3374,7 +3374,7 @@
{
const_pointer __p = data();
const_pointer __pe = __p + __sz;
- for (const_pointer __ps = __p + __pos; __p != __pe; ++__ps)
+ for (const_pointer __ps = __p + __pos; __ps != __pe; ++__ps)
if (!traits_type::eq(*__ps, __c))
return static_cast<size_type>(__ps - __p);
}
Index: test/strings/basic.string/string.ops/string_find.first.not.of/char_size.pass.cpp
===================================================================
--- test/strings/basic.string/string.ops/string_find.first.not.of/char_size.pass.cpp (revision 171297)
+++ test/strings/basic.string/string.ops/string_find.first.not.of/char_size.pass.cpp (working copy)
@@ -59,6 +59,8 @@
test(S("oselktgbcapndfjihrmq"), 'q', 21, S::npos);
test(S(""), 'q', S::npos);
+ test(S("q"), 'q', S::npos);
+ test(S("qqq"), 'q', S::npos);
test(S("csope"), 'q', 0);
test(S("gfsmthlkon"), 'q', 0);
test(S("laenfsbridchgotmkqpj"), 'q', 0);
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits