public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/31652] postfix increment semantics implemented incorrectly Date: Sat, 21 Apr 2007 22:49:00 -0000 [thread overview] Message-ID: <20070421224948.21620.qmail@sourceware.org> (raw) In-Reply-To: <bug-31652-14435@http.gcc.gnu.org/bugzilla/> ------- 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
next prev parent reply other threads:[~2007-04-21 22:49 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2007-04-21 22:39 [Bug c++/31652] New: " gcc-bugzilla at gcc dot gnu dot org 2007-04-21 22:49 ` pinskia at gcc dot gnu dot org [this message] 2007-04-22 5:40 ` [Bug c++/31652] " hayward at loup dot net 2007-04-22 6:04 ` pinskia at gcc dot gnu dot org 2007-04-22 15:37 ` hayward at loup dot net 2007-04-22 16:50 ` drow at gcc dot gnu dot org 2007-04-22 17:18 ` pinskia at gcc dot gnu dot org 2007-04-22 17:49 ` mmitchel at gcc dot gnu dot org 2007-04-22 17:49 ` drow at false dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20070421224948.21620.qmail@sourceware.org \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).