This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Bug in include/bits/stl_iterator.h?
On Thu, May 29, 2003 at 08:13:51PM -0400, Phil Edwards wrote:
> On Thu, May 29, 2003 at 04:03:56PM -0700, Nathan Myers wrote:
> >
> > // NB: Not required, but considered best practice.
> > if (__builtin_expect(__beg == _InIter(), 0))
> > __throw_logic_error("basic_string::_S_construct NULL not valid");
> [...]
> >
> > we should eliminate this check from basic_string.tcc and anywhere
> > else it (or its like) appears.
>
> I think you misspelled "we should find some other way of performing this
> highly useful check which catches a common programming error."
>
> Beginning (and even intermediate) users construct basic_strings from NULL
> all the time. Trust me, I get asked about it quite a bit. They seem to
> expect that the result should be equivalent to basic_string(""), which I
> agree would be wrong on many levels, but to not check the argument against
> NULL at all would just be needlessly confusing.
I agree that we are allowed, and encouraged, to specialize the
constructor for the case of raw _CharT pointers, and for any other
iterator type for which op== is defined when applied to default-
constructed objects. I don't agree that this check belongs in the
general constructor, for the reasons posted.
The check in the mainline case is a bug, and cannot be made correct
in its present form. It induces random failures in correct programs.
It has to be removed.
Adding checks to a specialization or specializations, or to the
single-argument constructor, would be a welcome quality of
implementation improvement, but we should not hold up fixing the
bug waiting for it.
Nathan Myers
ncm-nospam@cantrip.org