This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
Re: Another testsuite patch and a bug in string.find
- To: libstdc++ at sourceware dot cygnus dot com
- Subject: Re: Another testsuite patch and a bug in string.find
- From: Benjamin Kosnik <bkoz at cygnus dot com>
- Date: Tue, 13 Jun 2000 16:45:49 -0700 (PDT)
Nathan, did you get a chance to review this? If this is indeed a bug, or a
change in this behavior is necessary, then perhaps string should be fixed?
Also, please use diff -cp. (The relevant parts of the documenation have
been changed to plead for this instead of -up)
-benjamin
On Wed, 7 Jun 2000, Anthony Williams wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Here is a patch to testsuite/21_strings/find.cc, which I think makes
> it more standard compliant.
>
> The patch relates to empty strings. An empty string object contains
> no characters, so I believe that it should be found at all positions,
> and the following code should produce the given output. This
> highlights a bug in string.find, since libstdc++ produces the second
> set of output.
>
> include <iostream>
> #include <string>
>
> int main()
> {
> std::string a("hello");
> std::string b;
>
> for(unsigned i=0;i<=a.size();++i)
> std::cout<<a.find(b,i)<<std::endl;
> }
>
> Expected output:
> 0
> 1
> 2
> 3
> 4
> 4294967295
>
> libstdc++-v3 output:
> 5
> 5
> 5
> 5
> 5
> 5
>
> Anthony
>
> testsuite/21_strings/find.cc: Empty strings can be found at all
> positions
>
> Index: find.cc
> ===================================================================
> RCS file: /cvs/gcc/egcs/libstdc++-v3/testsuite/21_strings/find.cc,v
> retrieving revision 1.1
> diff -u -p -r1.1 find.cc
> - --- find.cc 2000/04/21 20:33:33 1.1
> +++ find.cc 2000/06/07 10:36:09
> @@ -56,21 +56,22 @@ bool test01(void)
> test &= csz01 == 8;
> csz01 = str01.find(str03, 12);
> test &= csz01 == npos;
> - - // It is implementation-defined if a given string contains an
> empty
> - - // string. The only two times a char_type() (== empty string)
> ending
> - - // element is required to be part of the string is on c_str() and
> - - // operator[size()] const: the indeterminate, stored state of the
> - - // string can vary, and not include a terminal char_type().
> +
> + // An empty string consists of no characters
> + // therefore it should be found at every point in a string,
> + // except beyond the end
> csz01 = str01.find(str04, 0);
> - - test &= csz01 == npos || csz01 == str01.size();
> + test &= csz01 == 0;
> csz01 = str01.find(str04, 5);
> - - test &= csz01 == npos || csz01 == str01.size();
> + test &= csz01 == 5;
> + csz01 = str01.find(str04, str01.size());
> + test &= csz01 == npos;
>
> // size_type find(const char* s, size_type pos, size_type n)
> const;
> csz01 = str01.find(str_lit01, 0, 3);
> test &= csz01 == 0;
> csz01 = str01.find(str_lit01, 3, 0);
> - - test &= csz01 == npos;
> + test &= csz01 == 3; // zero length string should be found at pos
>
> // size_type find(const char* s, size_type pos = 0) const;
> csz01 = str01.find(str_lit01);
> @@ -107,15 +108,15 @@ bool test01(void)
> csz01 = str01.find_first_of(str05, 4);
> test &= csz01 == 4;
>
> - - // It is implementation-defined if a given string contains an
> empty
> - - // string. The only two times a char_type() (== empty string)
> ending
> - - // element is required to be part of the string is on c_str() and
> - - // operator[size()] const: the indeterminate, stored state of the
> - - // string can vary, and not include a terminal char_type().
> + // An empty string consists of no characters
> + // therefore it should be found at every point in a string,
> + // except beyond the end
> + // However, str1.find_first_of(str2,pos) finds the first character
> in
> + // str1 (starting at pos) that exists in str2, which is none for
> empty str2
> csz01 = str01.find_first_of(str04, 0);
> - - test &= csz01 == npos || csz01 == str01.size();
> + test &= csz01 == npos;
> csz01 = str01.find_first_of(str04, 5);
> - - test &= csz01 == npos || csz01 == str01.size();
> + test &= csz01 == npos;
>
> // size_type find_first_of(const char* s, size_type pos, size_type
> n) const;
> csz01 = str01.find_first_of(str_lit01, 0, 3);
>
> PGP Fingerprint:
> 0E2D D32A 8732 DC31 804C D435 9BF0 F8FE 1C1B 9AD5
> PGP Key at: http://i3.yimg.com/3/c7e5ee24/g/68fc2307.asc
>
> -----BEGIN PGP SIGNATURE-----
> Version: PGPfreeware 6.5.1 for non-commercial use <http://www.pgp.com>
> Comment: PGP Key at: http://i3.yimg.com/3/c7e5ee24/g/68fc2307.asc
>
> iQA/AwUBOT4oWJvw+P4cG5rVEQIoSQCeOSpeFs2Nop06UHzMjZkVjI6a+mkAnRIY
> c7Xwm/ZImM9taKVPEJMj0MDt
> =kN6L
> -----END PGP SIGNATURE-----
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Talk to your friends online with Yahoo! Messenger.
> http://im.yahoo.com
>
>