Re: strange crash after assertion with std::map::iterator

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"Duane Hebert" <spoo@xxxxxxxxxx> wrote in message
news:eu0IVEVgHHA.4416@xxxxxxxxxxxxxxxxxxxx
"Igor Tandetnik" <itandetnik@xxxxxxxx> wrote in message
news:u1xYQ4DgHHA.1552@xxxxxxxxxxxxxxxxxxxxxxx
Mycroft Holmes <m.holmes@xxxxxxxxx> wrote:
the standard is very clear, but bizarre: I'd expect that
default-constructed iterators should behave as default-constructed
pointers (i.e. null)

What makes you think default-constructed pointer is NULL? Consider:

int* p;
assert(p == NULL); // will likely fail

Absolutely but I would have expected his original
example to just set t to false. Why assert?

Both the original example involving iterators, and my example above
involving pointers, exhibit undefined behavior. Modern STL
implementations help you diagnose some undefined behavior when using
STL, just like many Lint-like tools would help you diagnose some
undefined behavior caused by misuse of pointers.

And why
assert with iterator debugging disabled?

Nothing in the OP's message suggests that he or she has disabled
iterator debugging. In any case, I woudldn't be surprised if this check
is performed in debug build regardless of whether iterator debugging is
disabled or not. Why do you feel it matters?
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


.



Relevant Pages

  • Re: Standard containers (Was: Wiki by the committee closed?)
    ... Since a fixed size is certainly enough for an iterator, ... bad pointers, overflows, and maybe even CONTAINER_ERROR_INDEX), why not ... be reported if a container is accessed out of bounds. ... OUR list elements never change when you add something to our lists. ...
    (comp.std.c)
  • Re: abstract containers: does such a thing exist, conceptually?
    ... create a firewall between different types of lists. ... > behaviour by the additional pointers. ... I do not like much STL's style of iteration with iterator objects, ... For example, an array view for containers with ordered elements, ...
    (comp.object)
  • Re: strange crash after assertion with std::map::iterator
    ... involving pointers, exhibit undefined behavior. ... help you diagnose some undefined behavior when using STL, ... Lint-like tools would help you diagnose some undefined behavior caused by ... Nothing in the OP's message suggests that he or she has disabled iterator ...
    (microsoft.public.vc.stl)
  • Re: Pointer To A Vector Elements While Still Adding
    ... however there are cases that pointers get invalidated too in deque case. ... "surface" encapsulation about the type of the target container used, ... "surface" encapsulation can be provided by a typedef of the iterator type used. ...
    (comp.lang.cpp)
  • Re: Vector.Erase?
    ... So I tried to change it using iterator, but the result does not acting ... only on iterators, not pointers. ... vector::iterator was a pointer in the VC6 STL. ... gratuitously embed expressions with side-effects inside other expressions): ...
    (microsoft.public.vc.mfc)