This is the mail archive of the gcc-patches@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]

[WWW-patch] bugs.html: add note about missing sequence points


In view of PR 11751 which has an ever growing list of duplicates the
following patch adds a note about missing sequence points to the
non-bugs section of bugs.html.

Checked as valid XHTML.
Ok to commit?

Thanks to Wolfgang for several improvements!

Regards,
Volker


Index: bugs.html
===================================================================
RCS file: /cvs/gcc/wwwdocs/htdocs/bugs.html,v
retrieving revision 1.89
diff -u -p -r1.89 bugs.html
--- bugs.html	15 May 2004 09:43:51 -0000	1.89
+++ bugs.html	20 Aug 2004 14:23:21 -0000
@@ -458,6 +458,39 @@ for more information.</p></dd>
 <h2><a name="nonbugs_c">C</a></h2>
 
 <dl>
+<dt>Increment/decrement operator (<code>++</code>/<code>--</code>) not
+working as expected - a <a href="http://gcc.gnu.org/PR11751";>problem with
+many variations</a>.</dt>
+
+<dd><p>The following expressions have unpredictable results:</p>
+<blockquote><pre>
+x[i]=++i
+foo(i,++i)
+i*(++i)                 /* special case with foo=="operator*" */
+std::cout &lt;&lt; i &lt;&lt; ++i   /* foo(foo(std::cout,i),++i)          */
+</pre></blockquote>
+<p>since the <code>i</code> without increment can be evaluated before or
+after <code>++i</code>.</p>
+
+<p>The C and C++ standards have the notion of "sequence points". According
+to the standards, 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. Sequence points are for example
+the end of a statement and function calls. However, assignments and the
+comma between function arguments are not sequence points.</p>
+
+<p>Modifying a value twice between two sequence points as shown in the
+following examples is even worse:</p>
+<blockquote><pre>
+i=++i
+foo(++i,++i)
+(++i)*(++i)               /* special case with foo=="operator*" */
+std::cout &lt;&lt; ++i &lt;&lt; ++i   /* foo(foo(std::cout,++i),++i)        */
+</pre></blockquote>
+<p>This leads to undefined behavior (i.e. the compiler can do
+anything).</p></dd>
+
+
 <dt>Casting does not work as expected when optimization is turned on.</dt>
 
 <dd><p>This is often caused by a violation of aliasing rules, which are part
===================================================================



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