This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/31652] postfix increment semantics implemented incorrectly
- From: "pinskia at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 21 Apr 2007 22:49:48 -0000
- Subject: [Bug c++/31652] postfix increment semantics implemented incorrectly
- References: <bug-31652-14435@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #2 from pinskia at gcc dot gnu dot org 2007-04-21 23:49 -------
This is not a bug in GCC but instead a bug in your post fix increment operator:
C & operator++( int ) { v += 100; return *this; }
Really should be implemented as:
C operator++( int ) { C tmp = *this; v += 100; return tmp; }
Which is the correct way of implementing it. postfix increment returns a
rvalue and not a lvalue. See example in the C++ standard in 13.5.7/1.
Basically you just changed the semantics of post fix increment with the
operator overloader and changed it to be about the same as the pre incrementor
except incrementing by 100 instead of by 1.
Again this is not a bug in GCC but instead a bug in your code.
b = a++; is the same as doing:
b = a.operator++(0);
So if your operator++(int) returns *this, the result you are seeing is exactly
what is expected from the C++ standards point of view.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31652