cplusplus / CWG

Core Working Group
23 stars 7 forks source link

[intro.execution] p9 The meaing of next full-expression is underspecified #519

Open xmh0511 opened 3 months ago

xmh0511 commented 3 months ago

Full name of submitter (unless configured in github; will be published with the issue): Jim X

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.

int main(){
   int a = 1;
   a = 2;  // #1
   a = 3;  // #2
   for(int I = 0; I < 10; I++){
       a = I;  // #3
  }
}

Intuitively, it is easy to say #2 is the next full-expression to #1. How about every evaluation at #3 in each iteration? We seem to lack the wording to specify that the evaluation at #3 next time is the next full-expression to the one at last time.

Suggested Resolution

We may want to associate "next full-expression" with control flow?

frederick-vs-ja commented 3 months ago

Let's annotate the init-statement and expressions in the for statement with #F1~#F3. I think [stmt.for] (together with [stmt.while], [stmt.if], and [stmt.goto] if needed) clearly indicates that the next full-expression to #3 is the expression in #F2.

int main(){
   int a = 1;
   a = 2;  // #1
   a = 3;  // #2
   for(
        int I = 0; // #F1
        I < 10;    // #F2
        I++        // #F3
    ){
       a = I;  // #3
  }
}

Is there anything missing?

xmh0511 commented 3 months ago

Let's annotate the init-statement and expressions in the for statement with #F1~#F3. I think [stmt.for] (together with [stmt.while], [stmt.if], and [stmt.goto] if needed) clearly indicates that the next full-expression to #3 is the expression in #F2.

int main(){
   int a = 1;
   a = 2;  // #1
   a = 3;  // #2
   for(
        int I = 0; // #F1
        I < 10;    // #F2
        I++        // #F3
    ){
       a = I;  // #3
  }
}

Is there anything missing?

I think your argument doesn't conflict with what I proposed in the suggestion. I suggested that the next full-expression should be defined in terms of control flow. Moreover, the next full-expression seems to have a transitive relationship, that is the next full-expression to #1 can also be #F1.

#2 is an immediate next full-expression of #1.

t3nsor commented 3 months ago

"the next full-expression to be evaluated" means the next full-expression that will be evaluated, and which full-expression will be evaluated next is obviously determined by control flow, so, I do not think there is anything here that needs clarification.