Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the exact meaning of the statement "The expression e is used as a glvalue if and only if the initialization uses it as a glvalue" in [conv]/6

[conv]/6 (emphasis is mine):

The effect of any implicit conversion is the same as performing the corresponding declaration and initialization and then using the temporary variable as the result of the conversion. The result is an lvalue if T is an lvalue reference type or an rvalue reference to function type ([dcl.ref]), an xvalue if T is an rvalue reference to object type, and a prvalue otherwise. The expression e is used as a glvalue if and only if the initialization uses it as a glvalue.

What is the meaning of the highlighted statement above, in the context of this specific paragraph?

like image 632
John Kalane Avatar asked Oct 29 '22 23:10

John Kalane


1 Answers

The intent of that sentence is to clarify that an expression like i (where i is a variable) is not spuriously treated as a glvalue in contexts in which i is immediately converted to a prvalue.

For instance, in

int main() {
  const int j = 0;
  constexpr int i = j;
}

The second definition would be ill-formed if j was considered a glvalue, as j is not a permitted result of a constant expression. However, j is used as a prvalue since the initialization uses it as one, hence the other rule in the linked paragraph applies (and the definition is well-formed).

like image 104
Columbo Avatar answered Nov 15 '22 03:11

Columbo