§3.3.6/1 (C++11)
The declarative region of a namespace-definition is its namespace-body. The potential scope denoted by an original-namespace-name is the concatenation of the declarative regions established by each of the namespace-definitions in the same declarative region with that original-namespace-name....
The definition of a declarative region is as follows (§3.3.1/1):
Every name is introduced in some portion of program text called a declarative region, which is the largest part of the program in which that name is valid, that is, in which that name may be used as an unqualified name to refer to the same entity. ...
The two taken together would seem to imply that the name of a namespace can only be used (unqualified) inside the namespace body itself. But, clearly, this is false. So what does it mean for the declarative region of a namespace definition to be the body, when the name of the namespace can in fact be used (unqualified) outside the namespace body?
Also, I just don't understand this at all (re-quoted from above):
The potential scope denoted by an original-namespace-name is the concatenation of the declarative regions established by each of the namespace-definitions in the same declarative region with that original-namespace-name.
I think your confusion lies with the fact that you are mistakingly assuming that the text is about the namespace name itself, when the standard is really talking about names introduced inside the namespace in question.
The potential scope denoted by an original-namespace-name is the concatenation of the declarative regions established by each of the namespace-definitions in the same declarative region with that original-namespace-name.
The above might be easiest to describe with an example:
.--- namespace definition
| .--- original-namespace-name
v v
namespace N { <-------------------------------.
int x = 0; <---+--- declarative region (1)
} <-------------------------------------------'
.--- another namespace definition of `N`
| .--- original-namespace-name
v v
namespace N { <-------------------------------.
int y = x; <---+--- declarative region (2)
} <-------------------------------------------'
Note: The potential scope of int x is both (1) and (2), ie. "concatenation of the declarative regions" introduced.
In the example we have two namespace-definitions for the original-namespace-name N, we also have two declarative regions, but the "potential scope" inside the namespace named N is both (1), and (2).
As long as the namespace definitions themselves are in the same declarative region, and share the same original-namespace-name, they refer to the same namespace.
Introducing another such namespace definition will just add more room to the potential scope (by appending another declarative region) of the variables previously declared inside it.
potential scope, and declarative region; what are they?
a declarative region is the part of a program where a name can be referred to without being qualified.
The potential scope is the scope in which a name is potentially valid, it's the entire scope in which the name could refer to the same entity.
3.3.1p1Declarative regions and scope[basic.scope.declarative]Every name is introduced in some portion of program text called a declarative region, which is the largest part of the program in which that name is valid, that is, in which the name may be used as an unqualified name to refer to the same entity.
In general, each particular name is valid only within some possible discontiguous portion of program text called its scope. To determine the scope of a declaration, it is sometimes conventient to refer to the potential scope of a declaration.
The scope of a declaration is the same as its potential scope unless the potential scope contains another declaration of the same name. In that case the potential scope of the declaration in the inner (contained) declarative region is excluded from the scope of the declaration in the outer (containing) declarative region.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With