Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is an unnamed lvalue?

Tags:

c++

lvalue

I have seen in the draft N4268 a concept called "unnamed lvalue" in the striked-though part below

[ Note: Temporaries, unnamed lvalues, and named lvalues with no linkage are A temporary object is not an acceptable template-arguments when the corresponding template-parameter has reference type. [ Example: ... ] ]

I have searched a lot but neither stackoverflow nor google gave me an answer. I only found this post about value categories

What are rvalues, lvalues, xvalues, glvalues, and prvalues

But it didn't help.

like image 884
Pumkko Avatar asked Jul 16 '15 08:07

Pumkko


1 Answers

Not all lvalue expressions have names. In fact, the wording in N4296 gives us some examples:

For a non-type template-parameter of reference or pointer type, the value of the constant expression shall not refer to (or for a pointer type, shall not be the address of):

  • a subobject (1.8),
  • a temporary object (12.2),
  • a string literal (2.14.5),
  • the result of a typeid expression (5.2.8), or
  • a predefined func variable (8.4.1).

Furthermore, cppreference's information on value categories goes into detail about lvalues:

An lvalue is an expression that identifies a non-temporary object or a non-member function.

The following expressions are lvalues:

  • The name of a variable or function in scope, regardless of type, such as std::cin or std::endl. Even if the variable's type is rvalue reference, the expression consisting of its name is an lvalue expression.

  • Function call or overloaded operator expression if the function's or overloaded operator's return type is an lvalue reference, such as std::getline(std::cin, str) or std::cout << 1 or str1 = str2 or ++iter

  • Built-in pre-increment and pre-decrement, dereference, assignment and compound assignment, subscript (except on an array xvalue), member access (except for non-static non-reference members of xvalues, member enumerators, and non-static member functions), member access through pointer to data member if the left-hand operand is lvalue, comma operator if the right-hand operand is lvalue, ternary conditional if the second and third operands are lvalues.

  • Cast expression to lvalue reference type.

  • String literal

However, this is all irrelevant as the scope of the change is the proposal Allow constant evaluation for all non-type template arguments.

like image 139
user5122689 Avatar answered Oct 01 '22 22:10

user5122689