c++ - Class member qualified name lookup -
c++ - Class member qualified name lookup -
consider next code snippet:
class { int b[a::a]; //1, error void foo(){ int b = a::a; } //2, ok static const int = 5; }
clause 3.4.3.1/1 (qualified name lookup, class members) said:
if nested-name-specifier of qualified-id nominates class, name specified after nested-name-specifier looked in scope of class (10.2)
this implies name a
after nested-name-specifier both in //1
, in //2
looked in class scope.
clause 10.2 (member name lookup) said:
10.2/2
the next steps define result of name lookup fellow member name f in class scope c.
10.2/3
the lookup set f in c, called s(f, c)...
s(f, c) calculated follows:
10.2/4
if c contains declaration of name f, declaration set contains every declaration of f declared in c satisfies requirements of language build in lookup occurs.
the next unclear me:
from quotes cited implies both //1
, //2
same fellow member lookup rules shall applied. but different. why reasoning wrong?
note: know unqualified name lookup rules class scope. , understood behavior in next code snippet:
class { int b[a]; //error void foo(){ int b = a; } //ok static const int = 5; }
it because behavior described in sections 3.4.1/7 , 3.4.1/8 (unqualified name lookup).
the error because when int b[a::a];
beingness processed, a
not yet have symbol a
. @ point of compilation, a
still incomplete because have not reached closing }
of class definition yet. compiler doesn't "look ahead" see if future lines of source code contain definition of a
.
you can see reversing order of lines:
class { static const int = 5; int b[a::a]; // ok };
the function definition not have same problem because inline function bodies not compiled until after compilation of class definition. (sorry, don't have standard references handy this)
c++ class language-lawyer
Comments
Post a Comment