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

[intro.execution] p3 Is an operand applied with (built-in)conversions not a subexpression of an operation E? #5425

Open
xmh0511 opened this issue Apr 29, 2022 · 0 comments

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Apr 29, 2022

[intro.execution] p3 says

The immediate subexpressions of an expression E are

  • the constituent expressions of E's operands ([expr.prop]),
  • any function call that E implicitly invokes,
  • if E is a lambda-expression ([expr.prim.lambda]), the initialization of the entities captured by copy and the constituent expressions of the initializer of the init-captures,
  • if E is a function call or implicitly invokes a function, the constituent expressions of each default argument ([dcl.fct.default]) used in the call, or
  • if E creates an aggregate object ([dcl.init.aggr]), the constituent expressions of each default member initializer ([class.mem]) used in the initialization.

A subexpression of an expression E is an immediate subexpression of E or a subexpression of an immediate subexpression of E.

Consider this example:

int a = 0, b = 1;
a+b;  // #1

[basic.lval] p6 says

Whenever a glvalue appears as an operand of an operator that expects a prvalue for that operand, the lvalue-to-rvalue, array-to-pointer, or function-to-pointer standard conversions are applied to convert the expression to a prvalue.

So, any of the operands at #1 is the prvalue rather than a or b. According to the first bullet, such two prvalues are the operands. The constituent expression of the prvalue is itself. That means a and b are not subexpressions of the expression at #1. However, if the conversion is a user-defined conversion, the associated function call is a subexpression, as per the second bullet.

Moreover, this can introduce a doubt, when we say

the full-expression of its initialization is a constant expression when interpreted as a constant-expression

What can be subexpressions of the constant-expression when built-in conversion applies?

const int v = 0;
constexpr int i = v;

The initialization should be the prvalue that results from applying lvalue-to-rvalue conversion to v, In analogy to above, v is not a subexpression in that constant-expression.

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