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)