Return-Path: Delivered-To: apmail-incubator-stdcxx-dev-archive@www.apache.org Received: (qmail 67677 invoked from network); 5 Apr 2006 08:15:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 5 Apr 2006 08:15:36 -0000 Received: (qmail 12982 invoked by uid 500); 5 Apr 2006 08:15:36 -0000 Delivered-To: apmail-incubator-stdcxx-dev-archive@incubator.apache.org Received: (qmail 12965 invoked by uid 500); 5 Apr 2006 08:15:36 -0000 Mailing-List: contact stdcxx-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: stdcxx-dev@incubator.apache.org Delivered-To: mailing list stdcxx-dev@incubator.apache.org Received: (qmail 12954 invoked by uid 99); 5 Apr 2006 08:15:36 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Apr 2006 01:15:36 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: neutral (asf.osuosl.org: local policy) Received: from [208.30.140.160] (HELO moroha.quovadx.com) (208.30.140.160) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Apr 2006 01:15:35 -0700 Received: from bco-exchange.bco.roguewave.com (bco-exchange.bco.roguewave.com [172.19.31.48]) by moroha.quovadx.com (8.13.4/8.13.4) with ESMTP id k358F6dY010573 for ; Wed, 5 Apr 2006 08:15:06 GMT Received: from [193.16.179.107] (vpn13.bco.roguewave.com [10.70.10.13]) by bco-exchange.bco.roguewave.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2657.72) id 2JC2ABJ0; Wed, 5 Apr 2006 02:13:02 -0600 Message-ID: <44337C76.4020909@roguewave.com> Date: Wed, 05 Apr 2006 02:14:46 -0600 From: Martin Sebor User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915 X-Accept-Language: en-us, en MIME-Version: 1.0 To: stdcxx-dev@incubator.apache.org Subject: Re: basic_string::insert (iterator p, InputIterator first, InputIterator last) on Linux, gcc-4.0.2 References: <4D6A8407B7AC6F4D95B0E55C4E7C4C6203FA6E2D@exmsk.moscow.vdiweb.com> In-Reply-To: <4D6A8407B7AC6F4D95B0E55C4E7C4C6203FA6E2D@exmsk.moscow.vdiweb.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Anton Pevtsov wrote: > I updated the test for the replace method and reproduced the problem > discovered in the insert's test. Great, thanks for the detective work! Could you please open a new issue in Jira for this bug and add a link to this thread to it (as soon as it shows up in the archive)? Martin > This test fails on Widows, MSVC 7.1, build 11d and on SuSe Linux 9.1 gcc > 4.0.2: > > #include > #include > > static const char* test = "babc"; > > int main (void) > { > std::string s ("abc"); > s.replace (s.begin (), s.begin (), s.begin () + 1, s.begin () + 2); > > std::cout << "Expected " << test << " and got " << s << '\n'; > > return 0; > } > > The output is "Expected babc and got aabc". > > I investigated the problem and found that cause is in the > __rw_replace_aux function implementation in string.cc, line 566. > There is the following code (line 643): > > ... > // Current reference has enough room. > if (__rem) > traits_type::move(__s._C_data+__pos+__n2, > __s._C_data+__pos+__n, > __rem); > for (__d = 0; __d < (size_type)__n2; __d++) > traits_type::assign (*(__s._C_data+__pos+__d), *__first2++); > traits_type::assign (__s._C_data[__s._C_pref()->_C_size._C_size > = __len], value_type()); > ... > > For the exmaple above we have __pos = 0, __n2 = 1, __n = 0, __rem = 3, > and __s._C_data points to the begin of the "abc" string. > Note, that the iterator __first2 points to the same string, to symbol > 'b'. > > As first step this code moves the string and this operation results in > "aabc". > But the __first2 doesn't change - and now it points to the same place, > but there is the symbol 'a' ! > > Second step just copies the second 'a' to first 'a' in the string and > third step places zero at the end of string. > So, the result of the replace call differs from the expected one. > > > Thanks, > Anton Pevtsov > > > > -----Original Message----- > From: Martin Sebor [mailto:sebor@roguewave.com] > Sent: Tuesday, April 04, 2006 16:22 > To: stdcxx-dev@incubator.apache.org > Subject: Re: basic_string::insert (iterator p, InputIterator first, > InputIterator last) on Linux, gcc-4.0.2 > > > Anton Pevtsov wrote: > > [...] > >>It works fine on MSVC. The test fails on SuSe Linux 9.1 with gcc 4.0.2 > > >>only. And it looks like this is a problem on my local machine - Liviu >>couldn't reproduce it. When I finish the replace test I'll clean up >>all on my Linux machine and build the library from scratch again. > > > It might also be a problem with the compiler. I don't think I'll be able > to look into it until I get back. Working remotely from where I am > (Berlin, Germany) is excruciatingly slow and I cannot reproduce it on my > laptop. Try stepping through the code in the debugger to see if it > behaves correctly. > > Martin