This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: [Bug libstdc++/15523] Can't have vectors of vector::const_iterator
"bangerth at dealii dot org" <gcc-bugzilla@gcc.gnu.org> writes:
> ------- Additional Comments From bangerth at dealii dot org 2004-05-19 14:24 -------
> I see your point, although 24.1/5 only speaks about "most operations" and
> does not specifically rule out that we do the sensible thing here. I
> think my point is that I fail to see the value of this check, since it
> seems to be allowed to create such an iterator, but not to copy it. On
> the other hand, if we simply omitted the check we would fall over later
> if we ever tried to dereference it. The only thing that one would have
> to make sure is that the result of assigning a singular iterator to
> another iterator is again a singular iterator, but that should be what
> happens anyway if we simply copy all member variables.
>
> I don't feel strongly either way, since I already fixed my code to
> work around this, but I do feel that there are cases where one would
> like to generate a vector of singular iterators, and only after that
> assign individual values to them.
The obvious answer is that if one can't initialize a vector of
iterators to the 'right' value, one should initialize them to the
null iterator. :-) (I know, pointers are the only iterators for
which such a value exists.)
I think in most cases it would be sufficient to create an empty
vector, set it its vector<>::capacity(), and then push_back() new
values into it.
My naive expectation would be that -D_GLIBCXX_DEBUG_PEDANTIC would
cause an abort() for all dectectable undefined behavior. I think
most other users would expect this as well, *but* many probably
don't realize this extends to aborting on the copy of a singular
iterator, much less to aborting on the creation of the vector full
of singular iterators. OTOH, some users expect implementations to
report errors they don't know about.