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

[expr.call] The value computation of a function call and the evaluations of expressions within the function body are not specified #5476

Open
xmh0511 opened this issue May 19, 2022 · 1 comment

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented May 19, 2022

bool fun(){
  int a = 0, b, c  = 0;
  b =  ++a;
  return c = a++;
}
bool r = !fun();

The current wording does not seem to specify the value computation of the function call expression fun() and the evaluation of expressions within the function body(e.g. the side effect of expression a). Every evaluation of the expressions before return statement ought to be guaranteed to be sequenced before the value computation of the function call. There is no explicit wording for this point. The relevant wording about the sequence for function call are defined in [expr.call] and [basic.exec]
[expr.call] p8

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.

[intro.execution] p11

When invoking a function (whether or not the function is inline), every argument expression and the postfix expression designating the called function are sequenced before every expression or statement in the body of the called function. For each function invocation or evaluation of an await-expression F, each evaluation that does not occur within F but is evaluated on the same thread and as part of the same signal handler (if any) is either sequenced before all evaluations that occur within F or sequenced after all evaluations that occur within F;39 if F invokes or resumes a coroutine ([expr.await]), only evaluations subsequent to the previous suspension (if any) and prior to the next suspension (if any) are considered to occur within F.

Neither of them can clarify the above issue.

@xmh0511
Copy link
Contributor Author

xmh0511 commented May 23, 2022

Maybe, we could change [stmt.return] p5 to clarify this issue, that is:

The value computation or the copy-initialization of the returned reference of the call is considered part of the full-expression established by the operand of the return statement, which is sequenced before the destruction of temporaries at the end of the full-expression, which, in turn, is sequenced before the destruction of local variables ([stmt.jump]) of the block enclosing the return statement.

If we consider any evaluation of a prvalue(i.e. initialize result object or compute the value for operation) is a kind of value computation, see #5477

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