From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7515 invoked by alias); 19 Apr 2012 15:07:52 -0000 Received: (qmail 7503 invoked by uid 22791); 19 Apr 2012 15:07:51 -0000 X-SWARE-Spam-Status: No, hits=-4.3 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,KHOP_THREADED X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 19 Apr 2012 15:07:04 +0000 From: "vincent-gcc at vinc17 dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/51834] -Wsequence-point fails when convoluted expressions with multiple side effects are used Date: Thu, 19 Apr 2012 15:07:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vincent-gcc at vinc17 dot net X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-04/txt/msg01646.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D51834 --- Comment #4 from Vincent Lef=C3=A8vre 20= 12-04-19 15:06:58 UTC --- (In reply to comment #3) > (i++, i) + i is undefined. The sequence point only orders i++ and i insi= de the > parens, but not the operands of +. The third example is not undefined. The example is not (i++, i) + i, but (i, i++, i) + i, which is different because there is a sequence point before and after the i++. Still, there se= em to be disagreements on how to interpret the standard. There's a discussion "On sequence points and evaluation order" [1] in comp.std.c in 1995-12 (though that's a bit old), from which there are argum= ents to see the above expressions as UB. But "sequence points and evaluation ord= er" [2] in comp.lang.c in 2006-09 and a message from Keith Thompson [3] in comp.std.c in 2010-10 both contradict it: they both say something like sin(= x) + cos(x) has defined behavior even if sin() and cos() both modify errno (and = that these functions can be implemented by a macro, as long as it has a sequence point). [1] http://groups.google.com/group/comp.std.c/browse_thread/thread/d133e9c51bef= 572b/0b6545278c23d37f [2] http://groups.google.com/group/comp.lang.c/browse_thread/thread/c4bc836b783= b91be/d807a3ad7202b45b [3] http://groups.google.com/group/comp.std.c/msg/2dc8d2e8a0f4e572 What's strange is that GCC (4.4 to 4.7 at least) complains on (i ? (j |=3D 1, 0) : 0) | (i ? (j |=3D 1, 0) : 0); but not on (j |=3D 1, 0) | (j |=3D 1, 0); Contrary to GCC, I would say that the latter is UB (because from the root of the expression, one can evaluate both j |=3D 1 without getting a sequence p= oint yet -- GCC should have output a warning, and that's bug 51562), but not the former (similar to the errno case). Here's a simple testcase I've used, with more tests: int i, j; static inline int set_flag (void) { j |=3D 1; return 0; } #define FOO (i ? (j |=3D 1, 0) : 0) #define BAR (i ? set_flag () : 0) void fct (void) { FOO || FOO; FOO | FOO; BAR | BAR; set_flag () + set_flag (); j =3D (++i, j) + (j, ++i); return; } GCC 4.7.0 warns only for "FOO | FOO;" (and I think that's incorrect, as said above).