cplusplus / CWG

Core Working Group
23 stars 7 forks source link

[intro.execution] p3.1 It's unclear whether a postfix-expression of a function call is the operand of the function call #371

Open xmh0511 opened 1 year ago

xmh0511 commented 1 year ago

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

Consider this example:

consteval int fun(int x){
    return x;
}
int main(){
   int x = 0;
   fun(x);  // #1
}

The original rule in [expr.const] p13 in C++20 standard says:

An immediate invocation shall be a constant expression.

However, this rule has been changed to [expr.const] p17

An immediate-escalating expression shall appear only in an immediate-escalating function.

[expr.const] p16 says:

An expression or conversion is immediate-escalating if it is not initially in an immediate function context and it is either

a potentially-evaluated id-expression that denotes an immediate function that is not a subexpression of an immediate invocation, or

Since fun(x) is an immediate invocation, whether the rule applies to #1 is determined by whether fun is a subexpression of fun(x), that is, whether fun(x) is an immediate-escalating expression. However, [intro.execution] p3

The immediate subexpressions of an expression E are

  • the constituent expressions of E's operands ([expr.prop]),

is not clear whether the postfix-expression that consists of a function call is the operand of that function or not.

Suggested Resolution

The alternative rule may intend to take the place of the original rule in C++20 to say #1 is ill-formed. However, in the current wording, [expr.call] didn't tell whether the postfix-expression is the operand of the function call.

frederick-vs-ja commented 1 year ago

I think fun(x) already satisfies p16.2:

an immediate invocation that is not a constant expression and is not a subexpression of an immediate invocation.

xmh0511 commented 1 year ago

In this example, we may say fun(x) fall into p16.2, however, as exposed in the title, we didn't clearly say the operand of a function call.

frederick-vs-ja commented 1 year ago

Hmm... it seems that the term operand (other than unevaluated ones) is not properly defined via italic texts.