Created on 2005-03-24.00:00:00 last changed 196 months ago
[Voted into WP at the October, 2006 meeting.]
Proposed resolution (April, 2006):
Add a new paragraph following 6.5.3 [basic.lookup.unqual] paragraph 12:
If a variable member of a namespace is defined outside of the scope of its namespace then any name used in the definition of the variable member (after the declarator-id) is looked up as if the definition of the variable member occurred in its namespace. [Example:
namespace N { int i = 4; extern int j; } int i = 2; int N::j = i; // N::j == 4βend example]
Is the following code well-formed?
namespace N { int i; extern int j; } int N::j = i;
The question here is whether the lookup for i in the initializer of N::j finds the declaration in namespace N or not. Implementations differ on this question.
If N::j were a static data member of a class, the answer would be clear: both 6.5.3 [basic.lookup.unqual] paragraph 12 and 9.4 [dcl.init] paragraph 11 say that the initializer βis in the scope of the member's class.β There is no such provision for namespace members defined outside the namespace, however.
The reasoning given in 6.5.3 [basic.lookup.unqual] may be instructive:
A name used in the definition of a static data member of class X (11.4.9.3 [class.static.data]) (after the qualified-id of the static member) is looked up as if the name was used in a member function of X.
It is certainly the case that a name used in a function that is a member of a namespace is looked up in that namespace (6.5.3 [basic.lookup.unqual] paragraph 6), regardless of whether the definition is inside or outside that namespace. Initializers for namespace members should probably be looked up the same way.
History | |||
---|---|---|---|
Date | User | Action | Args |
2008-10-05 00:00:00 | admin | set | status: wp -> cd1 |
2007-05-06 00:00:00 | admin | set | status: dr -> wp |
2006-11-05 00:00:00 | admin | set | messages: + msg1426 |
2006-11-05 00:00:00 | admin | set | status: ready -> dr |
2006-04-22 00:00:00 | admin | set | status: review -> ready |
2005-10-22 00:00:00 | admin | set | messages: + msg1228 |
2005-10-22 00:00:00 | admin | set | status: open -> review |
2005-03-24 00:00:00 | admin | create |