https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97278

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
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. [Note:
All side effects of argument evaluations are sequenced before the function is
entered (see 6.9.1). — 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 ‘int main()’:
pr92278.C:9:42: warning: operation on ‘i’ may be undefined [-Wsequence-point]
    9 |     __builtin_printf ("%d\n", func(++i, i++));
      |                                         ~^~
pr92278.C:9:42: warning: operation on ‘i’ may be undefined [-Wsequence-point]

Reply via email to