Skip to content

[intro.execution] p12 does not specify how evaluations in a function's body are ordered with respect to what's sequenced after the function call #818

@xmh0511

Description

@xmh0511

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

[intro.execution] p12 says:

For each

  • function invocation,

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;

This rule is intended to mean that an evaluation A not occurring within F that would be otherwise unsequenced with F is indeterminately sequenced with F, that is, A cannot overlap with F. However, this rule does not specify how the order is in the following example:

int value = 0;
void fun(){
  value = 1; // #1
}
int main(){
  fun(); // #2 
  value = 2; // #3
}

[intro.execution] p12 means that #1 and #3 are indeterminately sequenced. [intro.execution] p11 says:

When invoking a function f (whether or not the function is inline), every argument expression and the postfix expression designating f are sequenced before every precondition assertion of f ([dcl.contract.func]), which in turn are sequenced before every expression or statement in the body of f, which in turn are sequenced before every postcondition assertion of f.

This means #2 is sequenced before #1; however, it still doesn't contribute to how #1 and #3 are ordered. The issue also exists in the inter-threaded happens-before case, for example, the function call F happens before another evaluation A; however, we cannot infer how the evaluations in F's body and A are ordered.

Suggested Resolution:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions