This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/32133] Post-increment gained unintuitive behaviour



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]