On 12/31/2012 09:11 PM, Howard Hinnant wrote:
On Dec 31, 2012, at 9:06 AM, Klaas de Vries <[email protected]> wrote:

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
Thanks much Klaas, committed revision 171321.

Could you supply a patch for CREDITS.TXT as well?

Howard

Supplying a patch for CREDITS.TXT

Regards,
Klaas

Index: CREDITS.TXT
===================================================================
--- CREDITS.TXT	(revision 171344)
+++ CREDITS.TXT	(working copy)
@@ -74,6 +74,10 @@
 N: Richard Smith
 D: Minor patches.
 
+N: Klaas de Vries
+E: klaas at klaasgaaf dot nl
+D: Minor bug fix.
+
 N: Zhang Xiongpang
 E: [email protected]
 D: Minor patches and bug fixes.
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to