1
int main(){
  int x = 0;  //#1
  {
    int x =1;  //#2
    x = 2;  //#3
  }
}

At the place marked with #3, the name lookup rules is applied to the id-expression x, which will find the entity declared in #2 rather than thex declared in #1, I think such an action sounds like the definition for glvalue, that is:
basic.lval#1.1

A glvalue is an expression whose evaluation determines the identity of an object, bit-field, or function.

In other words, the name lookup process determine the identity of x which appears at #3, which is the entity declared at #2. Although, the name lookup process occurs at compile time in general. However there's no rule in the standard that explicitly says the evaluation of expressions occur in run time or compile time, Right? So, I wonder whether the name lookup process can be considered as evaluation of glvalue? Moreover overload resolution for function(Such process is used to determine which the function is called), Isn't it a process that determine the identity of function?

Maybe, you can list a special case, that is reference, such as:

int main(){
  int v = 0;
  int& rf = v;
  {
    int v2 = 0;
    int& rf = v2;
    rf = 2;  //#3
  }
}

The name lookup rules also applies for references, however a reference is neither object, bit-field nor function. which is not listed in [basic.lval#1.1].

However the action of name lookup and the definition for glvalue indeed make confusion under some situations. If I misread [basic.lval#1.1], please correct me! Please point out which rule in the standard distinct such two concepts. Thanks.

In addition, if name lookup and glvalue evaluation are difference process, then I would argue that once the name lookup found the entity for an id-expression, Is it a redundant for such an id-expression to perform the evaluation of glvalue again?(such as x in my first example, the entity for name x is unique according to the ODR rule)

xmh0511
  • 7,010
  • 1
  • 9
  • 36
  • No. _Evaluate_ is plain English, and it is something done at runtume. _Name lookup_ is to find the thing denoted by the string of characters. An id-expression when evaluated is the thing found by name lookup, naturally. A glvalue need not be an id-expression. A glvalue need not even have a name. – Passer By Aug 31 '20 at 12:42
  • @PasserBy I tried to find the defintion for `evaluation` in the standard, however there's no any rule in [intro.execution](https://timsong-cpp.github.io/cppwp/n4659/intro.execution) says that `evaluation` must be occurred at runtime. I agree with `A glvalue need not be an id-expression. A glvalue need not even have a name.` such as `*pointer`. – xmh0511 Aug 31 '20 at 12:48
  • @PasserBy Could you tell me how to understand the sentence `A glvalue is an expression whose evaluation determines the identity of an object, bit-field, or function.` correctly? what's the `identity of an object, bit-field, or function`? – xmh0511 Aug 31 '20 at 12:49
  • _Identity_ is also plain English, to mean what that thing is. Two different things have different identities. A thing is known to be that specific thing by its identity. You evaluate `*p` to find out what it refers to, aka to find out its identity. – Passer By Aug 31 '20 at 12:55
  • @PasserBy I argue here is that once the name lookup find the entity for a name, it can not be changed to another things. Is it a redundant for such name to perform glvalue evaluation again? (the situation for id-expression) – xmh0511 Aug 31 '20 at 13:01
  • Notice how "evaluating" a glvalue does not give it's value, but only its identity. To actually evaluate that what glvalue refers to, we need to perform an [lvalue to rvalue conversion](https://stackoverflow.com/questions/20850536/lvalue-to-rvalue-implicit-conversion). *That* is what evaluates named entities. – rustyx Aug 31 '20 at 13:07
  • @rustyx l-to-r conversion only applies to `glvalue` when expect a prvalue expression. – xmh0511 Aug 31 '20 at 13:12
  • It's two orthogonal processes. Name lookup typically means for the compiler to match strings to internal syntax representations. Evaluating a glvalue expression is a runtime process that for objects typically mean to fetch from memory. Each name uniquely denotes an abstract thing and couldn't be changed at runtime, that's what compiled languages mean. But you still have to evaluate it, you're running on a physical computer. In fact, the analogy in standardese formalism is the _abstract machine_, because describing a program as a pure mathematical function doesn't make sense. – Passer By Aug 31 '20 at 14:06
  • @PasserBy Abstract machine would viewed as a physical computer to run the program? – xmh0511 Aug 31 '20 at 14:25
  • The abstract machine is the standard's way to specify a computer without constraining it to any particular physical computer/architecture. – Passer By Aug 31 '20 at 14:31

0 Answers0