public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/31401]  New: string find behaves strange when searching from npos
@ 2007-03-30 14:53 Ko dot vanderSloot at uvt dot nl
  2007-03-30 16:26 ` [Bug libstdc++/31401] " pcarlini at suse dot de
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Ko dot vanderSloot at uvt dot nl @ 2007-03-30 14:53 UTC (permalink / raw)
  To: gcc-bugs

the following program demonstrates, what I think, a flaw in std::string find.
According to me and (see comp.lang.c++ and c.l.c++.moderated) many others,
find( "astring", string::npos ) should always return string::npos.
But G++ seems to wrap around an start searching at the begin of the string.

sample program:
#include <iostream>
#include <string>

using namespace std;

int main(){
  string use = "anu";
  string::size_type pos1 = use.find_first_not_of( "an" );
  cerr << "pos1=" << pos1 << endl;
  pos1 = use.find( "a", string::npos );
  if ( pos1 == string::npos )
    cerr << "I expected this" << endl;
  else
    cerr << "problem because pos1=" << pos1 << endl;
  pos1 = use.find( "q", string::npos );
  if ( pos1 == string::npos )
    cerr << "I expected this" << endl;
  else
    cerr << "problem because pos1=" << pos1 << endl;
}


-- 
           Summary: string find behaves strange when searching from npos
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: Ko dot vanderSloot at uvt dot nl


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31401


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2007-07-11 18:20 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-30 14:53 [Bug libstdc++/31401] New: string find behaves strange when searching from npos Ko dot vanderSloot at uvt dot nl
2007-03-30 16:26 ` [Bug libstdc++/31401] " pcarlini at suse dot de
2007-03-30 16:52 ` pcarlini at suse dot de
2007-03-30 17:11 ` paolo at gcc dot gnu dot org
2007-03-30 17:12 ` paolo at gcc dot gnu dot org
2007-03-30 17:13 ` pcarlini at suse dot de
2007-04-02 10:09 ` paolo at gcc dot gnu dot org
2007-04-02 10:09 ` paolo at gcc dot gnu dot org
2007-07-11 18:20 ` pcarlini at suse dot de

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).