From Jason Turner

[namespace.udir]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpcpqanlu5/{from.md → to.md} +54 -24
tmp/tmpcpqanlu5/{from.md → to.md} RENAMED
@@ -4,26 +4,34 @@
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. When looking up a *namespace-name* in
10
- a *using-directive*, only namespace names are considered, see 
11
- [[basic.lookup.udir]]. The optional *attribute-specifier-seq* appertains
12
- to the *using-directive*.
 
 
 
 
13
 
14
  A *using-directive* specifies that the names in the nominated namespace
15
  can be used in the scope in which the *using-directive* appears after
16
  the *using-directive*. During unqualified name lookup (
17
  [[basic.lookup.unqual]]), the names appear as if they were declared in
18
  the nearest enclosing namespace which contains both the
19
- *using-directive* and the nominated namespace. In this context,
20
- “contains” means “contains directly or indirectly”.
 
 
21
 
22
  A *using-directive* does not add any members to the declarative region
23
  in which it appears.
24
 
 
 
25
  ``` cpp
26
  namespace A {
27
  int i;
28
  namespace B {
29
  namespace C {
@@ -48,15 +56,22 @@ namespace A {
48
  void f4() {
49
  i = 5; // ill-formed; neither i is visible
50
  }
51
  ```
52
 
 
 
53
  For unqualified lookup ([[basic.lookup.unqual]]), the *using-directive*
54
  is transitive: if a scope contains a *using-directive* that nominates a
55
  second namespace that itself contains *using-directive*s, the effect is
56
  as if the *using-directive*s from the second namespace also appeared in
57
- the first. For qualified lookup, see  [[namespace.qual]].
 
 
 
 
 
58
 
59
  ``` cpp
60
  namespace M {
61
  int i;
62
  }
@@ -95,21 +110,27 @@ namespace B {
95
  int n = j; // D::j hides B::j
96
  }
97
  }
98
  ```
99
 
100
- If a namespace is extended by an *extension-namespace-definition* after
101
- a *using-directive* for that namespace is given, the additional members
102
- of the extended namespace and the members of namespaces nominated by
103
- *using-directive*s in the *extension-namespace-definition* can be used
104
- after the *extension-namespace-definition*.
 
 
105
 
106
  If name lookup finds a declaration for a name in two different
107
  namespaces, and the declarations do not declare the same entity and do
108
- not declare functions, the use of the name is ill-formed. In particular,
109
- the name of a variable, function or enumerator does not hide the name of
110
- a class or enumeration declared in a different namespace. For example,
 
 
 
 
111
 
112
  ``` cpp
113
  namespace A {
114
  class X { };
115
  extern "C" int g();
@@ -123,24 +144,31 @@ namespace B {
123
  using namespace A;
124
  using namespace B;
125
 
126
  void f() {
127
  X(1); // error: name X found in two namespaces
128
- g(); // okay: name g refers to the same entity
129
- h(); // okay: overload resolution selects A::h
130
  }
131
  ```
132
 
 
 
133
  During overload resolution, all functions from the transitive search are
134
  considered for argument matching. The set of declarations found by the
135
- transitive search is unordered. In particular, the order in which
136
- namespaces were considered and the relationships among the namespaces
137
- implied by the *using-directive*s do not cause preference to be given to
138
- any of the declarations found by the search. An ambiguity exists if the
139
- best match finds two functions with the same signature, even if one is
140
- in a namespace reachable through *using-directive*s in the namespace of
141
- the other.[^7]
 
 
 
 
 
142
 
143
  ``` cpp
144
  namespace D {
145
  int d1;
146
  void f(char);
@@ -169,5 +197,7 @@ void f() {
169
  f(1); // error: ambiguous: D::f(int) or E::f(int)?
170
  f('a'); // OK: D::f(char)
171
  }
172
  ```
173
 
 
 
 
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
+
11
+ [*Note 1*: When looking up a *namespace-name* in a *using-directive*,
12
+ only namespace names are considered, see 
13
+ [[basic.lookup.udir]]. — *end note*]
14
+
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*]
27
 
28
  A *using-directive* does not add any members to the declarative region
29
  in which it appears.
30
 
31
+ [*Example 1*:
32
+
33
  ``` cpp
34
  namespace A {
35
  int i;
36
  namespace B {
37
  namespace C {
 
56
  void f4() {
57
  i = 5; // ill-formed; neither i is visible
58
  }
59
  ```
60
 
61
+ — *end example*]
62
+
63
  For unqualified lookup ([[basic.lookup.unqual]]), the *using-directive*
64
  is 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 
70
+ [[namespace.qual]]. — *end note*]
71
+
72
+ [*Example 2*:
73
 
74
  ``` cpp
75
  namespace M {
76
  int i;
77
  }
 
110
  int n = j; // D::j hides B::j
111
  }
112
  }
113
  ```
114
 
115
+ *end example*]
116
+
117
+ If a namespace is extended ([[namespace.def]]) after a
118
+ *using-directive* for that namespace is given, the additional members of
119
+ the extended namespace and the members of namespaces nominated by
120
+ *using-directive*s in the extending *namespace-definition* can be used
121
+ after the extending *namespace-definition*.
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 ill-formed.
126
+
127
+ [*Note 4*:
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();
 
144
  using namespace A;
145
  using namespace B;
146
 
147
  void f() {
148
  X(1); // error: name X found in two namespaces
149
+ g(); // OK: name g refers to the same entity
150
+ h(); // OK: overload resolution selects A::h
151
  }
152
  ```
153
 
154
+ — *end note*]
155
+
156
  During overload resolution, all functions from the transitive search are
157
  considered for argument matching. The set of declarations found by the
158
+ transitive search is unordered.
159
+
160
+ [*Note 5*: In particular, the order in which namespaces were considered
161
+ 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.[^7]
168
+
169
+ [*Example 3*:
170
 
171
  ``` cpp
172
  namespace D {
173
  int d1;
174
  void f(char);
 
197
  f(1); // error: ambiguous: D::f(int) or E::f(int)?
198
  f('a'); // OK: D::f(char)
199
  }
200
  ```
201
 
202
+ — *end example*]
203
+