Thread: I upgraded to g++ 4.2.2 and...

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    If x is not a valid iterator, i.e. x has the so-called singular value, then absolutely every operation except for assignment and destruction will invoke undefined behaviour. It is not true that x != y for any valid y, because the comparison invokes undefined behaviour. It is not true that x == x, because the comparison invokes undefined behaviour.

    To do anything with an iterator at all, it needs to have a valid value.

    24.1/5 says:
    Iterators can also have singular values that are not associated with any container. [...] Results of most expressions are undefined for singular values; the only exception is an assignment of a non-singular value to an iterator that holds a singular value. In this case the singular value is overwritten the same way as any other value. Dereferenceable and past-the-end values are always non-singular.
    I believe a later defect report clarified that destruction is a valid operation on a singular iterator.
    Last edited by CornedBee; 02-03-2008 at 02:15 PM.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by CornedBee View Post
    If x is not a valid iterator, i.e. x has the so-called singular value, then absolutely every operation except for assignment and destruction will invoke undefined behaviour. It is not true that x != y for any valid y, because the comparison invokes undefined behaviour. It is not true that x == x, because the comparison invokes undefined behaviour.
    I don't doubt you on this one. But it's a bunch of crap. If all such operations on invalid iterators are undefined, then there should have been no public default constructor for those iterators.

    The expression x == x should always be true, regardless of what x is, in my opinion.

Popular pages Recent additions subscribe to a feed