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

[stmt.expr] p1 There is not only a side effect but also value computation #5183

Open
xmh0511 opened this issue Jan 4, 2022 · 11 comments
Open

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Jan 4, 2022

[stmt.expr] p1

The expression is a discarded-value expression. All side effects from an expression statement are completed before the next statement is executed. An expression statement with the expression missing is called a null statement.

Consider this example

int a = 0;
int main(){ 
   a; // #1
   if(true); // #2  
}

There is no side effect applying to a at #1. Also, the value computation of a(determine the identity of the object) should be completed before the execution of the statement at #2. We only mention the side effect in [stmt.expr] p1. Maybe, we should say that

The evaluation in an expression statement is completed before the next statement is executed.

@languagelawyer
Copy link
Contributor

Is the difference observable?

@xmh0511
Copy link
Contributor Author

xmh0511 commented Jan 5, 2022

Is the difference observable?

Of course, it is. the provision merely mentions the side-effect. the evaluations of certain expressions only include value computation, this is different. Also, I think using evaluation is better than a sole side effect in any case.

@languagelawyer
Copy link
Contributor

languagelawyer commented Jan 5, 2022

Is the difference observable?

Of course, it is. the provision merely mentions the side-effect. the evaluations of certain expressions only include value computation, this is different.

Obviously, I wasn't asking: will the replacement of «side-effect» with «evaluation» be observable by a reader of the paragraph.

The second sentence of [stmt.expr]/1 is an artifact from C++98/03 times, now there is [intro.execution]/9:

Every value computation and side effect associated with a full-expression is sequenced before every value computation and side effect associated with the next full-expression to be evaluated.

and the expression of an expression-statement is a full-expression. I'd say the sentence from [stmt.expr]/1 should be removed.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Jan 5, 2022

@languagelawyer I don't think it can be removed. the next statement is not necessary to be a full-expression, such as the if statement, it is not a full-expression as per [intro.execution] p5. If the next statement was a full-expression, I would say [intro.execution]/9 can cover what [stmt.expr]/1 says.

@languagelawyer
Copy link
Contributor

languagelawyer commented Jan 5, 2022

the next statement is not necessary to be a full-expression, such as the if statement, it is not a full-expression

Why is this a problem? The condition inside if parentheses is a full-expression, which is next to be evaluated.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Jan 5, 2022

the next statement is not necessary to be a full-expression, such as the if statement, it is not a full-expression

Why is this a problem? The condition inside if parentheses is a full-expression.

The execution of the condition is within the period of the execution of the if statement. That's the difference. [stmt.expr] p1 try to state the execution relationship between an expression-statement and the other statement.

@languagelawyer
Copy link
Contributor

What is the difference between saying that the evaluation completes before the next statement is executed and that it completes before the evaluation of the next full-expression (when the next statement execution starts with the evaluation of this full-expression)?

@xmh0511
Copy link
Contributor Author

xmh0511 commented Jan 5, 2022

@languagelawyer Given an expression-statement A, a statement B that is not a full-expression, a full-expression C whose evaluation is within the execution of B.

Here are two utterances:

the evaluation of A is completed before the execution of B

the evaluation of A is completed before the evaluation of C

The first utterance can explicitly specify A -> B -> C. Instead, the second can only specify A-> C, we don't know whether A -> B or not. Symbol -> denotes completed before

@languagelawyer
Copy link
Contributor

Still don't get why one would need to know about A -> B or not, where symbol -> denotes completed before (whatever this means).

@xmh0511
Copy link
Contributor Author

xmh0511 commented Jan 5, 2022

@languagelawyer I would say I haven't yet figured out a relevant example for this case(i.e. why we want to know A -> B)😅 . Maybe, "coroutine" would involve this domain? Since we have given that a full-expression is sequenced before the next full-expression, why don't we give a similar restriction for the execution relationship between expression-statement and the other statement(in most cases, it does not overlap with the previous provision except the next statement is also a full-expression)?

@frederick-vs-ja
Copy link
Contributor

@languagelawyer Given an expression-statement A, a statement B that is not a full-expression, a full-expression C whose evaluation is within the execution of B.

Here are two utterances:

the evaluation of A is completed before the execution of B
the evaluation of A is completed before the evaluation of C

The first utterance can explicitly specify A -> B -> C. Instead, the second can only specify A-> C, we don't know whether A -> B or not. Symbol -> denotes completed before

I guess that the main problem is that "the execution of a statement" is not clearly specified. But I don't think we need to specify it, as doing so would not make difference.

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

3 participants