public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/32133]  New: Post-increment gained unintuitive behaviour
@ 2007-05-28 22:45 j dot witteveen at gmail dot com
  2007-05-28 22:47 ` [Bug c++/32133] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: j dot witteveen at gmail dot com @ 2007-05-28 22:45 UTC (permalink / raw)
  To: gcc-bugs

I noticed a change in the implementation of the post-increment (i++) operator
in gcc 4.0.1 (Apple build 5367).
The behaviour can be seen with the following code:
---
  i += i++;
---
In older versions (< 4) of g++ the 'original' variable is returned by ++,
meaning that the statement given has the effect of doubling the value of i. The
new version of ++ seems to return the 'copy', leading to i just being
incremented by one in the end.
The situation I think of as the most intuitive would be something like this:
---
  (i += i)++
---
I realise though that operator precedence prohibits such behaviour.
The following two lines demonstrate, however, why I think the old behaviour is
desired over the new one:
---
  (i++ < i); //Used to be true, now false
  (i > i++); //Idem
---
Modern versions even make this true:
---
  i++ == i++
---
Which, I think, is not what one wants.

Regards,
- Jouke


-- 
           Summary: Post-increment gained unintuitive behaviour
           Product: gcc
           Version: 4.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: j dot witteveen at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32133


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/32133] Post-increment gained unintuitive behaviour
  2007-05-28 22:45 [Bug c++/32133] New: Post-increment gained unintuitive behaviour j dot witteveen at gmail dot com
@ 2007-05-28 22:47 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-05-28 22:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2007-05-28 22:47 -------
You obviously did not read the bugs.html page which lists this as a nonbug:
http://gcc.gnu.org/bugs.html#nonbugs_c

Increment/decrement operator (++/--) not working as expected - a problem with
many variations.

    The following expressions have unpredictable results:

x[i]=++i
foo(i,++i)
i*(++i)                 /* special case with foo=="operator*" */
std::cout << i << ++i   /* foo(foo(std::cout,i),++i)          */

    since the i without increment can be evaluated before or after ++i.

    The C and C++ standards have the notion of "sequence points". Everything
that happens between two sequence points happens in an unspecified order, but
it has to happen after the first and before the second sequence point. The end
of a statement and a function call are examples for sequence points, whereas
assignments and the comma between function arguments are not.

    Modifying a value twice between two sequence points as shown in the
following examples is even worse:

i=++i
foo(++i,++i)
(++i)*(++i)               /* special case with foo=="operator*" */
std::cout << ++i << ++i   /* foo(foo(std::cout,++i),++i)        */

    This leads to undefined behavior (i.e. the compiler can do anything).

*** This bug has been marked as a duplicate of 11751 ***


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32133


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-05-28 22:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-28 22:45 [Bug c++/32133] New: Post-increment gained unintuitive behaviour j dot witteveen at gmail dot com
2007-05-28 22:47 ` [Bug c++/32133] " pinskia at gcc dot gnu dot org

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).