[Bug c++/51283] g++ yields different behaviour for postfix increment and decrement operators with fundamental types vs. classes
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Nov 23 13:21:00 GMT 2011
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51283
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-11-23 13:00:06 UTC ---
(In reply to comment #0)
> int i = 0;
> assert(i++ == i++); // OK
Undefined behaviour, try using -Wsequence-point
> int* p = 0;
> assert(p++ == p++); // OK
Undefined behaviour, try using -Wsequence-point
> vector<int> v(10, 10);
> vector<int>::iterator it = v.begin();
> assert(it++ == it++); // FAILS
If vector::iterator is a pointer that's undefined behaviour.
If it's a class type (as in libstdc++) then the assertion is meant to fail
because it's equivalent to:
auto it1 = it++;
auto it2 = it++;
assert( it1 == it2 ); // obviously wrong
> GCC should calculate expression (it++ == it++) with an object copy returned by
> the overload it.operator ++ (int) method like for the first two examples.
No it shouldn't.
More information about the Gcc-bugs
mailing list