public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "Ko dot vanderSloot at uvt dot nl" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/31401]  New: string find behaves strange when searching from npos
Date: Fri, 30 Mar 2007 14:53:00 -0000	[thread overview]
Message-ID: <bug-31401-14338@http.gcc.gnu.org/bugzilla/> (raw)

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	other threads:[~2007-03-30 14:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-30 14:53 Ko dot vanderSloot at uvt dot nl [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-31401-14338@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).