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

Reply via email to