tmp/tmpswtok9nz/{from.md → to.md}
RENAMED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
-
### Using directive <a id="namespace.udir">[[namespace.udir]]</a>
|
| 2 |
|
| 3 |
``` bnf
|
| 4 |
using-directive:
|
| 5 |
-
attribute-specifier-seqₒₚₜ
|
| 6 |
```
|
| 7 |
|
| 8 |
A *using-directive* shall not appear in class scope, but may appear in
|
| 9 |
namespace scope or in block scope.
|
| 10 |
|
|
@@ -15,12 +15,12 @@ only namespace names are considered, see
|
|
| 15 |
The optional *attribute-specifier-seq* appertains to the
|
| 16 |
*using-directive*.
|
| 17 |
|
| 18 |
A *using-directive* specifies that the names in the nominated namespace
|
| 19 |
can be used in the scope in which the *using-directive* appears after
|
| 20 |
-
the *using-directive*. During unqualified name lookup
|
| 21 |
-
[[basic.lookup.unqual]]
|
| 22 |
the nearest enclosing namespace which contains both the
|
| 23 |
*using-directive* and the nominated namespace.
|
| 24 |
|
| 25 |
[*Note 2*: In this context, “contains” means “contains directly or
|
| 26 |
indirectly”. — *end note*]
|
|
@@ -52,18 +52,18 @@ namespace A {
|
|
| 52 |
void f3() {
|
| 53 |
i = 5; // uses A::i
|
| 54 |
}
|
| 55 |
}
|
| 56 |
void f4() {
|
| 57 |
-
i = 5; //
|
| 58 |
}
|
| 59 |
```
|
| 60 |
|
| 61 |
— *end example*]
|
| 62 |
|
| 63 |
-
For unqualified lookup
|
| 64 |
-
|
| 65 |
second namespace that itself contains *using-directive*s, the effect is
|
| 66 |
as if the *using-directive*s from the second namespace also appeared in
|
| 67 |
the first.
|
| 68 |
|
| 69 |
[*Note 3*: For qualified lookup, see
|
|
@@ -112,25 +112,24 @@ namespace B {
|
|
| 112 |
}
|
| 113 |
```
|
| 114 |
|
| 115 |
— *end example*]
|
| 116 |
|
| 117 |
-
If a namespace is extended
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
|
|
|
|
|
|
| 122 |
|
| 123 |
If name lookup finds a declaration for a name in two different
|
| 124 |
namespaces, and the declarations do not declare the same entity and do
|
| 125 |
-
not declare functions, the use of the name is
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
In particular, the name of a variable, function or enumerator does not
|
| 130 |
-
hide the name of a class or enumeration declared in a different
|
| 131 |
-
namespace. For example,
|
| 132 |
|
| 133 |
``` cpp
|
| 134 |
namespace A {
|
| 135 |
class X { };
|
| 136 |
extern "C" int g();
|
|
@@ -162,11 +161,11 @@ and the relationships among the namespaces implied by the
|
|
| 162 |
*using-directive*s do not cause preference to be given to any of the
|
| 163 |
declarations found by the search. — *end note*]
|
| 164 |
|
| 165 |
An ambiguity exists if the best match finds two functions with the same
|
| 166 |
signature, even if one is in a namespace reachable through
|
| 167 |
-
*using-directive*s in the namespace of the other.[^
|
| 168 |
|
| 169 |
[*Example 3*:
|
| 170 |
|
| 171 |
``` cpp
|
| 172 |
namespace D {
|
|
|
|
| 1 |
+
### Using namespace directive <a id="namespace.udir">[[namespace.udir]]</a>
|
| 2 |
|
| 3 |
``` bnf
|
| 4 |
using-directive:
|
| 5 |
+
attribute-specifier-seqₒₚₜ using namespace nested-name-specifierₒₚₜ namespace-name ';'
|
| 6 |
```
|
| 7 |
|
| 8 |
A *using-directive* shall not appear in class scope, but may appear in
|
| 9 |
namespace scope or in block scope.
|
| 10 |
|
|
|
|
| 15 |
The optional *attribute-specifier-seq* appertains to the
|
| 16 |
*using-directive*.
|
| 17 |
|
| 18 |
A *using-directive* specifies that the names in the nominated namespace
|
| 19 |
can be used in the scope in which the *using-directive* appears after
|
| 20 |
+
the *using-directive*. During unqualified name lookup
|
| 21 |
+
[[basic.lookup.unqual]], the names appear as if they were declared in
|
| 22 |
the nearest enclosing namespace which contains both the
|
| 23 |
*using-directive* and the nominated namespace.
|
| 24 |
|
| 25 |
[*Note 2*: In this context, “contains” means “contains directly or
|
| 26 |
indirectly”. — *end note*]
|
|
|
|
| 52 |
void f3() {
|
| 53 |
i = 5; // uses A::i
|
| 54 |
}
|
| 55 |
}
|
| 56 |
void f4() {
|
| 57 |
+
i = 5; // error: neither i is visible
|
| 58 |
}
|
| 59 |
```
|
| 60 |
|
| 61 |
— *end example*]
|
| 62 |
|
| 63 |
+
For unqualified lookup [[basic.lookup.unqual]], the *using-directive* is
|
| 64 |
+
transitive: if a scope contains a *using-directive* that nominates a
|
| 65 |
second namespace that itself contains *using-directive*s, the effect is
|
| 66 |
as if the *using-directive*s from the second namespace also appeared in
|
| 67 |
the first.
|
| 68 |
|
| 69 |
[*Note 3*: For qualified lookup, see
|
|
|
|
| 112 |
}
|
| 113 |
```
|
| 114 |
|
| 115 |
— *end example*]
|
| 116 |
|
| 117 |
+
If a namespace is extended [[namespace.def]] after a *using-directive*
|
| 118 |
+
for that namespace is given, the additional members of the extended
|
| 119 |
+
namespace and the members of namespaces nominated by *using-directive*s
|
| 120 |
+
in the extending *namespace-definition* can be used after the extending
|
| 121 |
+
*namespace-definition*.
|
| 122 |
+
|
| 123 |
+
[*Note 4*:
|
| 124 |
|
| 125 |
If name lookup finds a declaration for a name in two different
|
| 126 |
namespaces, and the declarations do not declare the same entity and do
|
| 127 |
+
not declare functions or function templates, the use of the name is
|
| 128 |
+
ill-formed [[basic.lookup]]. In particular, the name of a variable,
|
| 129 |
+
function or enumerator does not hide the name of a class or enumeration
|
| 130 |
+
declared in a different namespace. For example,
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
``` cpp
|
| 133 |
namespace A {
|
| 134 |
class X { };
|
| 135 |
extern "C" int g();
|
|
|
|
| 161 |
*using-directive*s do not cause preference to be given to any of the
|
| 162 |
declarations found by the search. — *end note*]
|
| 163 |
|
| 164 |
An ambiguity exists if the best match finds two functions with the same
|
| 165 |
signature, even if one is in a namespace reachable through
|
| 166 |
+
*using-directive*s in the namespace of the other.[^11]
|
| 167 |
|
| 168 |
[*Example 3*:
|
| 169 |
|
| 170 |
``` cpp
|
| 171 |
namespace D {
|