- tmp/tmpe_sej0ox/{from.md → to.md} +18 -163
tmp/tmpe_sej0ox/{from.md → to.md}
RENAMED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
### Namespace definition <a id="namespace.def">[[namespace.def]]</a>
|
| 2 |
|
|
|
|
|
|
|
| 3 |
``` bnf
|
| 4 |
namespace-name:
|
| 5 |
identifier
|
| 6 |
namespace-alias
|
| 7 |
```
|
|
@@ -37,22 +39,20 @@ enclosing-namespace-specifier:
|
|
| 37 |
``` bnf
|
| 38 |
namespace-body:
|
| 39 |
declaration-seqₒₚₜ
|
| 40 |
```
|
| 41 |
|
| 42 |
-
Every *namespace-definition* shall
|
| 43 |
[[basic.scope.namespace]].
|
| 44 |
|
| 45 |
-
In a *named-namespace-definition*, the *identifier* is the name of the
|
| 46 |
-
namespace.
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
as a *namespace-name* into the declarative region in which the
|
| 53 |
-
*named-namespace-definition* appears.
|
| 54 |
|
| 55 |
Because a *namespace-definition* contains *declaration*s in its
|
| 56 |
*namespace-body* and a *namespace-definition* is itself a *declaration*,
|
| 57 |
it follows that *namespace-definition*s can be nested.
|
| 58 |
|
|
@@ -69,34 +69,10 @@ namespace Outer {
|
|
| 69 |
}
|
| 70 |
```
|
| 71 |
|
| 72 |
— *end example*]
|
| 73 |
|
| 74 |
-
The *enclosing namespaces* of a declaration are those namespaces in
|
| 75 |
-
which the declaration lexically appears, except for a redeclaration of a
|
| 76 |
-
namespace member outside its original namespace (e.g., a definition as
|
| 77 |
-
specified in [[namespace.memdef]]). Such a redeclaration has the same
|
| 78 |
-
enclosing namespaces as the original declaration.
|
| 79 |
-
|
| 80 |
-
[*Example 2*:
|
| 81 |
-
|
| 82 |
-
``` cpp
|
| 83 |
-
namespace Q {
|
| 84 |
-
namespace V {
|
| 85 |
-
void f(); // enclosing namespaces are the global namespace, Q, and Q::V
|
| 86 |
-
class C { void m(); };
|
| 87 |
-
}
|
| 88 |
-
void V::f() { // enclosing namespaces are the global namespace, Q, and Q::V
|
| 89 |
-
extern void h(); // ... so this declares Q::V::h
|
| 90 |
-
}
|
| 91 |
-
void V::C::m() { // enclosing namespaces are the global namespace, Q, and Q::V
|
| 92 |
-
}
|
| 93 |
-
}
|
| 94 |
-
```
|
| 95 |
-
|
| 96 |
-
— *end example*]
|
| 97 |
-
|
| 98 |
If the optional initial `inline` keyword appears in a
|
| 99 |
*namespace-definition* for a particular namespace, that namespace is
|
| 100 |
declared to be an *inline namespace*. The `inline` keyword may be used
|
| 101 |
on a *namespace-definition* that extends a namespace only if it was
|
| 102 |
previously used on the *namespace-definition* that initially declared
|
|
@@ -104,33 +80,30 @@ the *namespace-name* for that namespace.
|
|
| 104 |
|
| 105 |
The optional *attribute-specifier-seq* in a *named-namespace-definition*
|
| 106 |
appertains to the namespace being defined or extended.
|
| 107 |
|
| 108 |
Members of an inline namespace can be used in most respects as though
|
| 109 |
-
they were members of the enclosing namespace. Specifically,
|
| 110 |
-
namespace and its enclosing namespace are both added to the
|
| 111 |
-
associated namespaces used in argument-dependent lookup
|
| 112 |
[[basic.lookup.argdep]] whenever one of them is, and a *using-directive*
|
| 113 |
[[namespace.udir]] that names the inline namespace is implicitly
|
| 114 |
inserted into the enclosing namespace as for an unnamed namespace
|
| 115 |
[[namespace.unnamed]]. Furthermore, each member of the inline namespace
|
| 116 |
-
can subsequently be partially specialized [[temp.
|
| 117 |
explicitly instantiated [[temp.explicit]], or explicitly specialized
|
| 118 |
[[temp.expl.spec]] as though it were a member of the enclosing
|
| 119 |
namespace. Finally, looking up a name in the enclosing namespace via
|
| 120 |
explicit qualification [[namespace.qual]] will include members of the
|
| 121 |
-
inline namespace
|
| 122 |
-
|
| 123 |
|
| 124 |
These properties are transitive: if a namespace `N` contains an inline
|
| 125 |
namespace `M`, which in turn contains an inline namespace `O`, then the
|
| 126 |
members of `O` can be used as though they were members of `M` or `N`.
|
| 127 |
The *inline namespace set* of `N` is the transitive closure of all
|
| 128 |
-
inline namespaces in `N`.
|
| 129 |
-
set of namespaces consisting of the innermost non-inline namespace
|
| 130 |
-
enclosing an inline namespace `O`, together with any intervening inline
|
| 131 |
-
namespaces.
|
| 132 |
|
| 133 |
A *nested-namespace-definition* with an *enclosing-namespace-specifier*
|
| 134 |
`E`, *identifier* `I` and *namespace-body* `B` is equivalent to
|
| 135 |
|
| 136 |
``` cpp
|
|
@@ -138,11 +111,11 @@ namespace E { \opt{inline} namespace I { B } }
|
|
| 138 |
```
|
| 139 |
|
| 140 |
where the optional `inline` is present if and only if the *identifier*
|
| 141 |
`I` is preceded by `inline`.
|
| 142 |
|
| 143 |
-
[*Example
|
| 144 |
|
| 145 |
``` cpp
|
| 146 |
namespace A::inline B::C {
|
| 147 |
int i;
|
| 148 |
}
|
|
@@ -201,123 +174,5 @@ void h() {
|
|
| 201 |
}
|
| 202 |
```
|
| 203 |
|
| 204 |
— *end example*]
|
| 205 |
|
| 206 |
-
#### Namespace member definitions <a id="namespace.memdef">[[namespace.memdef]]</a>
|
| 207 |
-
|
| 208 |
-
A declaration in a namespace `N` (excluding declarations in nested
|
| 209 |
-
scopes) whose *declarator-id* is an *unqualified-id* [[dcl.meaning]],
|
| 210 |
-
whose *class-head-name* [[class.pre]] or *enum-head-name* [[dcl.enum]]
|
| 211 |
-
is an *identifier*, or whose *elaborated-type-specifier* is of the form
|
| 212 |
-
*class-key* *attribute-specifier-seq*ₒₚₜ *identifier*
|
| 213 |
-
[[dcl.type.elab]], or that is an *opaque-enum-declaration*, declares (or
|
| 214 |
-
redeclares) its *unqualified-id* or *identifier* as a member of `N`.
|
| 215 |
-
|
| 216 |
-
[*Note 1*: An explicit instantiation [[temp.explicit]] or explicit
|
| 217 |
-
specialization [[temp.expl.spec]] of a template does not introduce a
|
| 218 |
-
name and thus may be declared using an *unqualified-id* in a member of
|
| 219 |
-
the enclosing namespace set, if the primary template is declared in an
|
| 220 |
-
inline namespace. — *end note*]
|
| 221 |
-
|
| 222 |
-
[*Example 1*:
|
| 223 |
-
|
| 224 |
-
``` cpp
|
| 225 |
-
namespace X {
|
| 226 |
-
void f() { ... } // OK: introduces X::f()
|
| 227 |
-
|
| 228 |
-
namespace M {
|
| 229 |
-
void g(); // OK: introduces X::M::g()
|
| 230 |
-
}
|
| 231 |
-
using M::g;
|
| 232 |
-
void g(); // error: conflicts with X::M::g()
|
| 233 |
-
}
|
| 234 |
-
```
|
| 235 |
-
|
| 236 |
-
— *end example*]
|
| 237 |
-
|
| 238 |
-
Members of a named namespace can also be defined outside that namespace
|
| 239 |
-
by explicit qualification [[namespace.qual]] of the name being defined,
|
| 240 |
-
provided that the entity being defined was already declared in the
|
| 241 |
-
namespace and the definition appears after the point of declaration in a
|
| 242 |
-
namespace that encloses the declaration’s namespace.
|
| 243 |
-
|
| 244 |
-
[*Example 2*:
|
| 245 |
-
|
| 246 |
-
``` cpp
|
| 247 |
-
namespace Q {
|
| 248 |
-
namespace V {
|
| 249 |
-
void f();
|
| 250 |
-
}
|
| 251 |
-
void V::f() { ... } // OK
|
| 252 |
-
void V::g() { ... } // error: g() is not yet a member of V
|
| 253 |
-
namespace V {
|
| 254 |
-
void g();
|
| 255 |
-
}
|
| 256 |
-
}
|
| 257 |
-
|
| 258 |
-
namespace R {
|
| 259 |
-
void Q::V::g() { ... } // error: R doesn't enclose Q
|
| 260 |
-
}
|
| 261 |
-
```
|
| 262 |
-
|
| 263 |
-
— *end example*]
|
| 264 |
-
|
| 265 |
-
If a friend declaration in a non-local class first declares a class,
|
| 266 |
-
function, class template or function template[^10] the friend is a
|
| 267 |
-
member of the innermost enclosing namespace. The friend declaration does
|
| 268 |
-
not by itself make the name visible to unqualified lookup
|
| 269 |
-
[[basic.lookup.unqual]] or qualified lookup [[basic.lookup.qual]].
|
| 270 |
-
|
| 271 |
-
[*Note 2*: The name of the friend will be visible in its namespace if a
|
| 272 |
-
matching declaration is provided at namespace scope (either before or
|
| 273 |
-
after the class definition granting friendship). — *end note*]
|
| 274 |
-
|
| 275 |
-
If a friend function or function template is called, its name may be
|
| 276 |
-
found by the name lookup that considers functions from namespaces and
|
| 277 |
-
classes associated with the types of the function arguments
|
| 278 |
-
[[basic.lookup.argdep]]. If the name in a friend declaration is neither
|
| 279 |
-
qualified nor a *template-id* and the declaration is a function or an
|
| 280 |
-
*elaborated-type-specifier*, the lookup to determine whether the entity
|
| 281 |
-
has been previously declared shall not consider any scopes outside the
|
| 282 |
-
innermost enclosing namespace.
|
| 283 |
-
|
| 284 |
-
[*Note 3*: The other forms of friend declarations cannot declare a new
|
| 285 |
-
member of the innermost enclosing namespace and thus follow the usual
|
| 286 |
-
lookup rules. — *end note*]
|
| 287 |
-
|
| 288 |
-
[*Example 3*:
|
| 289 |
-
|
| 290 |
-
``` cpp
|
| 291 |
-
// Assume f and g have not yet been declared.
|
| 292 |
-
void h(int);
|
| 293 |
-
template <class T> void f2(T);
|
| 294 |
-
namespace A {
|
| 295 |
-
class X {
|
| 296 |
-
friend void f(X); // A::f(X) is a friend
|
| 297 |
-
class Y {
|
| 298 |
-
friend void g(); // A::g is a friend
|
| 299 |
-
friend void h(int); // A::h is a friend
|
| 300 |
-
// ::h not considered
|
| 301 |
-
friend void f2<>(int); // ::f2<>(int) is a friend
|
| 302 |
-
};
|
| 303 |
-
};
|
| 304 |
-
|
| 305 |
-
// A::f, A::g and A::h are not visible here
|
| 306 |
-
X x;
|
| 307 |
-
void g() { f(x); } // definition of A::g
|
| 308 |
-
void f(X) { ... } // definition of A::f
|
| 309 |
-
void h(int) { ... } // definition of A::h
|
| 310 |
-
// A::f, A::g and A::h are visible here and known to be friends
|
| 311 |
-
}
|
| 312 |
-
|
| 313 |
-
using A::x;
|
| 314 |
-
|
| 315 |
-
void h() {
|
| 316 |
-
A::f(x);
|
| 317 |
-
A::X::f(x); // error: f is not a member of A::X
|
| 318 |
-
A::X::Y::g(); // error: g is not a member of A::X::Y
|
| 319 |
-
}
|
| 320 |
-
```
|
| 321 |
-
|
| 322 |
-
— *end example*]
|
| 323 |
-
|
|
|
|
| 1 |
### Namespace definition <a id="namespace.def">[[namespace.def]]</a>
|
| 2 |
|
| 3 |
+
#### General <a id="namespace.def.general">[[namespace.def.general]]</a>
|
| 4 |
+
|
| 5 |
``` bnf
|
| 6 |
namespace-name:
|
| 7 |
identifier
|
| 8 |
namespace-alias
|
| 9 |
```
|
|
|
|
| 39 |
``` bnf
|
| 40 |
namespace-body:
|
| 41 |
declaration-seqₒₚₜ
|
| 42 |
```
|
| 43 |
|
| 44 |
+
Every *namespace-definition* shall inhabit a namespace scope
|
| 45 |
[[basic.scope.namespace]].
|
| 46 |
|
| 47 |
+
In a *named-namespace-definition* D, the *identifier* is the name of the
|
| 48 |
+
namespace. The *identifier* is looked up by searching for it in the
|
| 49 |
+
scopes of the namespace A in which D appears and of every element of the
|
| 50 |
+
inline namespace set of A. If the lookup finds a *namespace-definition*
|
| 51 |
+
for a namespace N, D *extends* N, and the target scope of D is the scope
|
| 52 |
+
to which N belongs. If the lookup finds nothing, the *identifier* is
|
| 53 |
+
introduced as a *namespace-name* into A.
|
|
|
|
|
|
|
| 54 |
|
| 55 |
Because a *namespace-definition* contains *declaration*s in its
|
| 56 |
*namespace-body* and a *namespace-definition* is itself a *declaration*,
|
| 57 |
it follows that *namespace-definition*s can be nested.
|
| 58 |
|
|
|
|
| 69 |
}
|
| 70 |
```
|
| 71 |
|
| 72 |
— *end example*]
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
If the optional initial `inline` keyword appears in a
|
| 75 |
*namespace-definition* for a particular namespace, that namespace is
|
| 76 |
declared to be an *inline namespace*. The `inline` keyword may be used
|
| 77 |
on a *namespace-definition* that extends a namespace only if it was
|
| 78 |
previously used on the *namespace-definition* that initially declared
|
|
|
|
| 80 |
|
| 81 |
The optional *attribute-specifier-seq* in a *named-namespace-definition*
|
| 82 |
appertains to the namespace being defined or extended.
|
| 83 |
|
| 84 |
Members of an inline namespace can be used in most respects as though
|
| 85 |
+
they were members of the innermost enclosing namespace. Specifically,
|
| 86 |
+
the inline namespace and its enclosing namespace are both added to the
|
| 87 |
+
set of associated namespaces used in argument-dependent lookup
|
| 88 |
[[basic.lookup.argdep]] whenever one of them is, and a *using-directive*
|
| 89 |
[[namespace.udir]] that names the inline namespace is implicitly
|
| 90 |
inserted into the enclosing namespace as for an unnamed namespace
|
| 91 |
[[namespace.unnamed]]. Furthermore, each member of the inline namespace
|
| 92 |
+
can subsequently be partially specialized [[temp.spec.partial]],
|
| 93 |
explicitly instantiated [[temp.explicit]], or explicitly specialized
|
| 94 |
[[temp.expl.spec]] as though it were a member of the enclosing
|
| 95 |
namespace. Finally, looking up a name in the enclosing namespace via
|
| 96 |
explicit qualification [[namespace.qual]] will include members of the
|
| 97 |
+
inline namespace even if there are declarations of that name in the
|
| 98 |
+
enclosing namespace.
|
| 99 |
|
| 100 |
These properties are transitive: if a namespace `N` contains an inline
|
| 101 |
namespace `M`, which in turn contains an inline namespace `O`, then the
|
| 102 |
members of `O` can be used as though they were members of `M` or `N`.
|
| 103 |
The *inline namespace set* of `N` is the transitive closure of all
|
| 104 |
+
inline namespaces in `N`.
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
A *nested-namespace-definition* with an *enclosing-namespace-specifier*
|
| 107 |
`E`, *identifier* `I` and *namespace-body* `B` is equivalent to
|
| 108 |
|
| 109 |
``` cpp
|
|
|
|
| 111 |
```
|
| 112 |
|
| 113 |
where the optional `inline` is present if and only if the *identifier*
|
| 114 |
`I` is preceded by `inline`.
|
| 115 |
|
| 116 |
+
[*Example 2*:
|
| 117 |
|
| 118 |
``` cpp
|
| 119 |
namespace A::inline B::C {
|
| 120 |
int i;
|
| 121 |
}
|
|
|
|
| 174 |
}
|
| 175 |
```
|
| 176 |
|
| 177 |
— *end example*]
|
| 178 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|