You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by Farid Zaripov <Fa...@epam.com> on 2007/06/27 20:49:50 UTC

21.string.rfind.cpp test fail reason

  The problem in 21.string.rfind.cpp test is invoking
string::rfind(const value_type* ptr, size_type off = npos, size_type
count)
with count == string::max_size() + 1 (21.string.rfind.cpp lines
413-416).
The method throws length_error() exception (line 756 file string.cc) but
test
not expected any exceptions.

Farid.

RE: 21.string.rfind.cpp test fail reason

Posted by Farid Zaripov <Fa...@epam.com>.
> -----Original Message-----
> From: Martin Sebor [mailto:msebor@gmail.com] On Behalf Of Martin Sebor
> Sent: Tuesday, July 03, 2007 7:02 AM
> To: stdcxx-dev@incubator.apache.org
> Subject: Re: 21.string.rfind.cpp test fail reason
> 
> >   The test deals with exceptions (the all exceptions are catched).
> > I mean that concrete test line not expected any exception 
> and issues 
> > rw_error() when length_error() catched.
> 
> I don't see any calls to rw_error() in 21.string.rfind.cpp 
> but you probably meant rw_assert().

  Yes, I mean rw_assert(). Sorry.  

> rfind() is not required 
> to and shouldn't throw under any conditions. There's no 
> efficient way for all the overloads of rfind() to throw 
> consistently under the same conditions so it should just 
> return npos instead. We need a Jira issue to track this change.

  http://issues.apache.org/jira/browse/STDCXX-466

Farid.

Re: 21.string.rfind.cpp test fail reason

Posted by Martin Sebor <se...@roguewave.com>.
Farid Zaripov wrote:
>> -----Original Message-----
>> From: Martin Sebor [mailto:msebor@gmail.com] On Behalf Of Martin Sebor
>> Sent: Friday, June 29, 2007 8:24 AM
>> To: stdcxx-dev@incubator.apache.org
>> Subject: Re: 21.string.rfind.cpp test fail reason
>>
>> Farid Zaripov wrote:
>>>   The problem in 21.string.rfind.cpp test is invoking 
>>> string::rfind(const value_type* ptr, size_type off = npos, size_type
>>> count)
>>> with count == string::max_size() + 1 (21.string.rfind.cpp lines 
>>> 413-416).
>>> The method throws length_error() exception (line 756 file 
>> string.cc) 
>>> but test not expected any exceptions.
>> The test should definitely be prepared to deal with 
>> exceptions, even if they are not required or allowed.
> 
>   The test deals with exceptions (the all exceptions are catched).
> I mean that concrete test line not expected any exception and
> issues rw_error() when length_error() catched.

I don't see any calls to rw_error() in 21.string.rfind.cpp but you
probably meant rw_assert(). rfind() is not required to and shouldn't
throw under any conditions. There's no efficient way for all the
overloads of rfind() to throw consistently under the same conditions
so it should just return npos instead. We need a Jira issue to track
this change.

Btw., library issue 625 highlights some of the problems in string
due to the inconsistent use of Effects and Returns clauses:
http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#625

Martin

RE: 21.string.rfind.cpp test fail reason

Posted by Farid Zaripov <Fa...@epam.com>.
> -----Original Message-----
> From: Martin Sebor [mailto:msebor@gmail.com] On Behalf Of Martin Sebor
> Sent: Friday, June 29, 2007 8:24 AM
> To: stdcxx-dev@incubator.apache.org
> Subject: Re: 21.string.rfind.cpp test fail reason
> 
> Farid Zaripov wrote:
> >   The problem in 21.string.rfind.cpp test is invoking 
> > string::rfind(const value_type* ptr, size_type off = npos, size_type
> > count)
> > with count == string::max_size() + 1 (21.string.rfind.cpp lines 
> > 413-416).
> > The method throws length_error() exception (line 756 file 
> string.cc) 
> > but test not expected any exceptions.
> 
> The test should definitely be prepared to deal with 
> exceptions, even if they are not required or allowed.

  The test deals with exceptions (the all exceptions are catched).
I mean that concrete test line not expected any exception and
issues rw_error() when length_error() catched.

Farid.

Re: 21.string.rfind.cpp test fail reason

Posted by Martin Sebor <se...@roguewave.com>.
Farid Zaripov wrote:
>   The problem in 21.string.rfind.cpp test is invoking
> string::rfind(const value_type* ptr, size_type off = npos, size_type
> count)
> with count == string::max_size() + 1 (21.string.rfind.cpp lines
> 413-416).
> The method throws length_error() exception (line 756 file string.cc) but
> test
> not expected any exceptions.

The test should definitely be prepared to deal with exceptions, even
if they are not required or allowed. In this case I think it would be
perfectly reasonable not to throw and return npos to indicate that
the substring wasn't found. In fact, I believe would be more useful
than to throw.  IIRC, Anton and I discussed this but I don't see
an issue about it in Jira. This thread might be relevant:

http://www.mail-archive.com/stdcxx-dev@incubator.apache.org/msg01244.html

Martin