This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Bug in include/bits/stl_iterator.h?
- From: Nathan Myers <ncm-nospam at cantrip dot org>
- To: libstdc++ at gcc dot gnu dot org
- Date: Thu, 29 May 2003 16:03:56 -0700
- Subject: Bug in include/bits/stl_iterator.h?
In include/bits/stl_iterator.h, we have
/**
* The default constructor gives an undefined state to this
* %iterator.
*/
reverse_iterator() { }
And in include/bits/basic_string.tcc (line 144), _S_construct, we have
// NB: Not required, but considered best practice.
if (__builtin_expect(__beg == _InIter(), 0))
__throw_logic_error("basic_string::_S_construct NULL not valid");
It's entirely possible for a valid input value __beg to accidently
match the (uninitialized) value that shows up in the temporary value
_InIter() constructed on the stack, such as when constructing a
string from a reverse_iterator on valid pointer values.
The effect of this problem is that valid user programs may throw,
nondeterministically.
According to 24.1 [lib.iterator.requirements] par 5 (p510), it's not
allowed to pass a default-constructed iterator to op==. Therefore,
we should eliminate this check from basic_string.tcc and anywhere
else it (or its like) appears. Not only does it rely on behavior
defined neither by the standard nor by us, it also breaks correct
programs in an unpredictable and not necessarily repeatable way.
Comments?
Nathan Myers
ncm-nospam@cantrip.org