This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
Re: <string> - warning messages
- To: libstdc++@sourceware.cygnus.com
- Subject: Re: <string> - warning messages
- From: Nathan Myers <ncm@best.com>
- Date: Tue, 29 Jun 1999 09:21:49 -0700 (PDT)
- Reply-To: libstdc++@sourceware.cygnus.com
Vadim wrote:
> I see more problems here than that.
> It looks like an attempt to check validity of the range [__beg, end).
>
> _M_replace contains similar piece of code (bits/string.tcc:424):
> size_type __dist_new = static_cast<size_type>(distance(__j1, __j2));
>
> In the case of negative distance in both cases it is converted to big
> unsigned
> value - in the first case by _Rep::_S_create(__range, __a) call.
>
> If it is bigger than max_size() than length_error will be thrown,
> otherwise we'll
> have undefined behavior predicted in Standard.
It's a lot worse than that. This makes the function incompatible
with real Input iterators, because measuring the distance
uses them up. They're one-pass items.
> I would like to know what is supposed to happen in such cases.
> (e.g.
> string s1("some text");
> string s2(s1.end(), s1.begin());
> )
It's impossible in general to check iterators, and generally a
mistake to try. We could partial-specialize on string- and
vector- "checked iterators", but they would slow performance enough
that it would need to be a compile-time option.
Nathan Myers
ncm@cantrip.org