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

[conv] / 6 (emphasis mine):

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

What is the meaning of the above statement in the context of this particular paragraph?

+4
source share
1 answer

The purpose of this sentence is to clarify that an expression of type i(where iis a variable) is not falsely regarded as a glvalue in contexts in which it is iimmediately converted to prvalue.

For example, in

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

The second definition will be poorly formed if jit is considered the value of gl, since jit is not a valid result of a constant expression . However, it is jused as a prvalue, since initialization uses it as a whole, therefore, another rule is applied in the related paragraph (and the definition is correctly formed).

+2
source

Source: https://habr.com/ru/post/1648887/


All Articles