Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[intro.execution] p8 Sequenced before and the subexpressions thereof #5861

Open
xmh0511 opened this issue Sep 22, 2022 · 0 comments
Open

[intro.execution] p8 Sequenced before and the subexpressions thereof #5861

xmh0511 opened this issue Sep 22, 2022 · 0 comments

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Sep 22, 2022

Consider this example

   int a[2][3] = {{0,1,2},{3,4,5}};
   int i = 0;
   auto r = a[i++][i++];

[expr.sub] p1 says

The postfix-expression and the initialization of the object parameter of any applicable subscript operator function is sequenced before each expression in the expression-list and also before any default argument.

In this example, a is sequenced before the first i++, and the a[i++] is sequenced before the second i++. [intro.execution] p8 says

An expression X is said to be sequenced before an expression Y if every value computation and every side effect associated with the expression X is sequenced before every value computation and every side effect associated with the expression Y.

Do these two rules guarantee the side effect of the first i++(which is the subexpression of a[i++]) is sequenced before the value computation of the second i++? The meaning of the "associated with" is not clear enough here.

Improvement

An expression X is said to be sequenced before an expression Y if every value computation and every side effect associated with the expression X is sequenced before every value computation and every side effect associated with the expression Y (including these of the subexpressions thereof, if any).

With this improvement, the side effect of the subexpressions is ascribed to the evaluation of the post-expression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant