From Jason Turner

[namespace.qual]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp0atui3tx/{from.md → to.md} +57 -36
tmp/tmp0atui3tx/{from.md → to.md} RENAMED
@@ -1,30 +1,31 @@
1
  #### Namespace members <a id="namespace.qual">[[namespace.qual]]</a>
2
 
3
- If the *nested-name-specifier* of a *qualified-id* nominates a
4
- namespace, the name specified after the *nested-name-specifier* is
5
- looked up in the scope of the namespace. If a *qualified-id* starts with
6
- `::`, the name after the `::` is looked up in the global namespace. In
7
- either case, the names in a *template-argument* of a *template-id* are
8
- looked up in the context in which the entire *postfix-expression*
9
- occurs.
10
 
11
  For a namespace `X` and name `m`, the namespace-qualified lookup set
12
  S(X, m) is defined as follows: Let S'(X, m) be the set of all
13
  declarations of `m` in `X` and the inline namespace set of `X` (
14
  [[namespace.def]]). If S'(X, m) is not empty, S(X, m) is S'(X, m);
15
  otherwise, S(X, m) is the union of S(Nᵢ, m) for all namespaces Nᵢ
16
- nominated by *using-directives* in `X` and its inline namespace set.
17
 
18
  Given `X::m` (where `X` is a user-declared namespace), or given `::m`
19
  (where X is the global namespace), if S(X, m) is the empty set, the
20
  program is ill-formed. Otherwise, if S(X, m) has exactly one member, or
21
  if the context of the reference is a *using-declaration* (
22
  [[namespace.udecl]]), S(X, m) is the required set of declarations of
23
  `m`. Otherwise if the use of `m` is not one that allows a unique
24
  declaration to be chosen from S(X, m), the program is ill-formed.
25
 
 
 
26
  ``` cpp
27
  int x;
28
  namespace Y {
29
  void f(float);
30
  void h(int);
@@ -53,38 +54,38 @@ namespace AB {
53
  void g();
54
  }
55
 
56
  void h()
57
  {
58
- AB::g(); // g is declared directly in AB,
59
- // therefore S is { AB::g() } and AB::g() is chosen
60
- AB::f(1); // f is not declared directly in AB so the rules are
61
- // applied recursively to A and B;
62
- // namespace Y is not searched and Y::f(float)
63
- // is not considered;
64
- // S is { A::f(int), B::f(char) } and overload
65
- // resolution chooses A::f(int)
66
  AB::f('c'); // as above but resolution chooses B::f(char)
67
 
68
- AB::x++; // x is not declared directly in AB, and
69
- // is not declared in A or B , so the rules are
70
- // applied recursively to Y and Z,
71
- // S is { } so the program is ill-formed
72
- AB::i++; // i is not declared directly in AB so the rules are
73
- // applied recursively to A and B,
74
- // S is { A::i , B::i } so the use is ambiguous
75
- // and the program is ill-formed
76
- AB::h(16.8); // h is not declared directly in AB and
77
- // not declared directly in A or B so the rules are
78
- // applied recursively to Y and Z,
79
- // S is { Y::h(int), Z::h(double) } and overload
80
- // resolution chooses Z::h(double)
81
  }
82
  ```
83
 
 
 
 
 
84
  The same declaration found more than once is not an ambiguity (because
85
- it is still a unique declaration). For example:
 
 
86
 
87
  ``` cpp
88
  namespace A {
89
  int a;
90
  }
@@ -102,11 +103,11 @@ namespace BC {
102
  using namespace C;
103
  }
104
 
105
  void f()
106
  {
107
- BC::a++; // OK: S is { A::a, A::a }
108
  }
109
 
110
  namespace D {
111
  using A::a;
112
  }
@@ -116,14 +117,20 @@ namespace BD {
116
  using namespace D;
117
  }
118
 
119
  void g()
120
  {
121
- BD::a++; // OK: S is { A::a, A::a }
122
  }
123
  ```
124
 
 
 
 
 
 
 
125
  Because each referenced namespace is searched at most once, the
126
  following is well-defined:
127
 
128
  ``` cpp
129
  namespace B {
@@ -139,25 +146,29 @@ namespace B {
139
  using namespace A;
140
  }
141
 
142
  void f()
143
  {
144
- A::a++; // OK: a declared directly in A, S is {A::a}
145
- B::a++; // OK: both A and B searched (once), S is {A::a}
146
- A::b++; // OK: both A and B searched (once), S is {B::b}
147
- B::b++; // OK: b declared directly in B, S is {B::b}
148
  }
149
  ```
150
 
 
 
151
  During the lookup of a qualified namespace member name, if the lookup
152
  finds more than one declaration of the member, and if one declaration
153
  introduces a class name or enumeration name and the other declarations
154
  either introduce the same variable, the same enumerator or a set of
155
  functions, the non-type name hides the class or enumeration name if and
156
  only if the declarations are from the same namespace; otherwise (the
157
  declarations are from different namespaces), the program is ill-formed.
158
 
 
 
159
  ``` cpp
160
  namespace A {
161
  struct x { };
162
  int x;
163
  int y;
@@ -173,10 +184,12 @@ namespace C {
173
  int i = C::x; // OK, A::x (of type int)
174
  int j = C::y; // ambiguous, A::y or B::y
175
  }
176
  ```
177
 
 
 
178
  In a declaration for a namespace member in which the *declarator-id* is
179
  a *qualified-id*, given that the *qualified-id* for the namespace member
180
  has the form
181
 
182
  ``` bnf
@@ -185,24 +198,30 @@ nested-name-specifier unqualified-id
185
 
186
  the *unqualified-id* shall name a member of the namespace designated by
187
  the *nested-name-specifier* or of an element of the inline namespace
188
  set ([[namespace.def]]) of that namespace.
189
 
 
 
190
  ``` cpp
191
  namespace A {
192
  namespace B {
193
  void f1(int);
194
  }
195
  using namespace B;
196
  }
197
  void A::f1(int){ } // ill-formed, f1 is not a member of A
198
  ```
199
 
 
 
200
  However, in such namespace member declarations, the
201
  *nested-name-specifier* may rely on *using-directive*s to implicitly
202
  provide the initial part of the *nested-name-specifier*.
203
 
 
 
204
  ``` cpp
205
  namespace A {
206
  namespace B {
207
  void f1(int);
208
  }
@@ -217,5 +236,7 @@ namespace C {
217
  using namespace A;
218
  using namespace C::D;
219
  void B::f1(int){ } // OK, defines A::B::f1(int)
220
  ```
221
 
 
 
 
1
  #### Namespace members <a id="namespace.qual">[[namespace.qual]]</a>
2
 
3
+ If the *nested-name-specifier* of a *qualified-id* nominates a namespace
4
+ (including the case where the *nested-name-specifier* is `::`, i.e.,
5
+ nominating the global namespace), the name specified after the
6
+ *nested-name-specifier* is looked up in the scope of the namespace. The
7
+ names in a *template-argument* of a *template-id* are looked up in the
8
+ context in which the entire *postfix-expression* occurs.
 
9
 
10
  For a namespace `X` and name `m`, the namespace-qualified lookup set
11
  S(X, m) is defined as follows: Let S'(X, m) be the set of all
12
  declarations of `m` in `X` and the inline namespace set of `X` (
13
  [[namespace.def]]). If S'(X, m) is not empty, S(X, m) is S'(X, m);
14
  otherwise, S(X, m) is the union of S(Nᵢ, m) for all namespaces Nᵢ
15
+ nominated by *using-directive*s in `X` and its inline namespace set.
16
 
17
  Given `X::m` (where `X` is a user-declared namespace), or given `::m`
18
  (where X is the global namespace), if S(X, m) is the empty set, the
19
  program is ill-formed. Otherwise, if S(X, m) has exactly one member, or
20
  if the context of the reference is a *using-declaration* (
21
  [[namespace.udecl]]), S(X, m) is the required set of declarations of
22
  `m`. Otherwise if the use of `m` is not one that allows a unique
23
  declaration to be chosen from S(X, m), the program is ill-formed.
24
 
25
+ [*Example 1*:
26
+
27
  ``` cpp
28
  int x;
29
  namespace Y {
30
  void f(float);
31
  void h(int);
 
54
  void g();
55
  }
56
 
57
  void h()
58
  {
59
+ AB::g(); // g is declared directly in AB, therefore S is { `AB::g()` } and AB::g() is chosen
60
+
61
+ AB::f(1); // f is not declared directly in AB so the rules are applied recursively to A and B;
62
+ // namespace Y is not searched and Y::f(float) is not considered;
63
+ // S is { `A::f(int)`, `B::f(char)` } and overload resolution chooses A::f(int)
64
+
 
 
65
  AB::f('c'); // as above but resolution chooses B::f(char)
66
 
67
+ AB::x++; // x is not declared directly in AB, and is not declared in A or B, so the rules
68
+ // are applied recursively to Y and Z, S is { } so the program is ill-formed
69
+
70
+ AB::i++; // i is not declared directly in AB so the rules are applied recursively to A and B,
71
+ // S is { `A::i`, `B::i` } so the use is ambiguous and the program is ill-formed
72
+
73
+ AB::h(16.8); // h is not declared directly in AB and not declared directly in A or B so the rules
74
+ // are applied recursively to Y and Z, S is { `Y::h(int)`, `Z::h(double)` } and
75
+ // overload resolution chooses Z::h(double)
 
 
 
 
76
  }
77
  ```
78
 
79
+ — *end example*]
80
+
81
+ [*Note 1*:
82
+
83
  The same declaration found more than once is not an ambiguity (because
84
+ it is still a unique declaration).
85
+
86
+ [*Example 2*:
87
 
88
  ``` cpp
89
  namespace A {
90
  int a;
91
  }
 
103
  using namespace C;
104
  }
105
 
106
  void f()
107
  {
108
+ BC::a++; // OK: S is { `A::a`, `A::a` }
109
  }
110
 
111
  namespace D {
112
  using A::a;
113
  }
 
117
  using namespace D;
118
  }
119
 
120
  void g()
121
  {
122
+ BD::a++; // OK: S is { `A::a`, `A::a` }
123
  }
124
  ```
125
 
126
+ — *end example*]
127
+
128
+ — *end note*]
129
+
130
+ [*Example 3*:
131
+
132
  Because each referenced namespace is searched at most once, the
133
  following is well-defined:
134
 
135
  ``` cpp
136
  namespace B {
 
146
  using namespace A;
147
  }
148
 
149
  void f()
150
  {
151
+ A::a++; // OK: a declared directly in A, S is { `A::a` }
152
+ B::a++; // OK: both A and B searched (once), S is { `A::a` }
153
+ A::b++; // OK: both A and B searched (once), S is { `B::b` }
154
+ B::b++; // OK: b declared directly in B, S is { `B::b` }
155
  }
156
  ```
157
 
158
+ — *end example*]
159
+
160
  During the lookup of a qualified namespace member name, if the lookup
161
  finds more than one declaration of the member, and if one declaration
162
  introduces a class name or enumeration name and the other declarations
163
  either introduce the same variable, the same enumerator or a set of
164
  functions, the non-type name hides the class or enumeration name if and
165
  only if the declarations are from the same namespace; otherwise (the
166
  declarations are from different namespaces), the program is ill-formed.
167
 
168
+ [*Example 4*:
169
+
170
  ``` cpp
171
  namespace A {
172
  struct x { };
173
  int x;
174
  int y;
 
184
  int i = C::x; // OK, A::x (of type int)
185
  int j = C::y; // ambiguous, A::y or B::y
186
  }
187
  ```
188
 
189
+ — *end example*]
190
+
191
  In a declaration for a namespace member in which the *declarator-id* is
192
  a *qualified-id*, given that the *qualified-id* for the namespace member
193
  has the form
194
 
195
  ``` bnf
 
198
 
199
  the *unqualified-id* shall name a member of the namespace designated by
200
  the *nested-name-specifier* or of an element of the inline namespace
201
  set ([[namespace.def]]) of that namespace.
202
 
203
+ [*Example 5*:
204
+
205
  ``` cpp
206
  namespace A {
207
  namespace B {
208
  void f1(int);
209
  }
210
  using namespace B;
211
  }
212
  void A::f1(int){ } // ill-formed, f1 is not a member of A
213
  ```
214
 
215
+ — *end example*]
216
+
217
  However, in such namespace member declarations, the
218
  *nested-name-specifier* may rely on *using-directive*s to implicitly
219
  provide the initial part of the *nested-name-specifier*.
220
 
221
+ [*Example 6*:
222
+
223
  ``` cpp
224
  namespace A {
225
  namespace B {
226
  void f1(int);
227
  }
 
236
  using namespace A;
237
  using namespace C::D;
238
  void B::f1(int){ } // OK, defines A::B::f1(int)
239
  ```
240
 
241
+ — *end example*]
242
+