From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E690F3861875; Sat, 3 Oct 2020 08:32:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E690F3861875 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/97278] increment or decrement operator on the same object Date: Sat, 03 Oct 2020 08:32: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-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_status resolution cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 03 Oct 2020 08:32:02 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97278 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID CC| |jakub at gcc dot gnu.org --- Comment #1 from Jakub Jelinek --- Your testcase is invalid, even C++17 and later, therefore you can get any result. While C++17 added some extra evaluation ordering rules over earlier C++ revisions, for calls, i.e. postfix-expression ( expression-list_opt_ ) the standard now says: The postfix-expression is sequenced before each expression in the expression-list and any default argument. The initialization of a parameter, including every associated value computation and side effect, is indeterminately sequenced with respect to that of any other parameter. [Not= e: All side effects of argument evaluations are sequenced before the function = is entered (see 6.9.1). =E2=80=94 end note] so while side-effects in the postfix-expression need to be evaluated before= the arguments, there is no sequence point between the arguments. g++ even warns about this with -Wall: pr92278.C: In function =E2=80=98int main()=E2=80=99: pr92278.C:9:42: warning: operation on =E2=80=98i=E2=80=99 may be undefined = [-Wsequence-point] 9 | __builtin_printf ("%d\n", func(++i, i++)); | ~^~ pr92278.C:9:42: warning: operation on =E2=80=98i=E2=80=99 may be undefined = [-Wsequence-point]=