This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/49679] Increment/decrement operator (++/--) not working as expected
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 8 Jul 2011 17:57:57 +0000
- Subject: [Bug c++/49679] Increment/decrement operator (++/--) not working as expected
- Auto-submitted: auto-generated
- References: <bug-49679-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49679
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-07-08 17:57:09 UTC ---
The code has undefined behaviour because there are no sequence points between
the increments, see http://c-faq.com/expr/seqpoints.html
GCC even warns you:
seq.cc: In function 'int main(int, char**)':
seq.cc:19:15: warning: operation on 'a' may be undefined [-Wsequence-point]
seq.cc:19:15: warning: operation on 'a' may be undefined [-Wsequence-point]
seq.cc:20:15: warning: operation on 'b' may be undefined [-Wsequence-point]
seq.cc:20:15: warning: operation on 'b' may be undefined [-Wsequence-point]
You should use -Wall if the compiler seems to be doing something you don't
understand, it might explain why.