From Jason Turner

[basic.lookup.unqual]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpub3_pdc1/{from.md → to.md} +66 -35
tmp/tmpub3_pdc1/{from.md → to.md} RENAMED
@@ -11,12 +11,15 @@ become visible in a namespace enclosing the *using-directive*; see 
11
  described in  [[basic.lookup.unqual]], the declarations from the
12
  namespace nominated by the *using-directive* are considered members of
13
  that enclosing namespace.
14
 
15
  The lookup for an unqualified name used as the *postfix-expression* of a
16
- function call is described in  [[basic.lookup.argdep]]. For purposes of
17
- determining (during parsing) whether an expression is a
 
 
 
18
  *postfix-expression* for a function call, the usual name lookup rules
19
  apply. The rules in  [[basic.lookup.argdep]] have no effect on the
20
  syntactic interpretation of an expression. For example,
21
 
22
  ``` cpp
@@ -24,37 +27,39 @@ typedef int f;
24
  namespace N {
25
  struct A {
26
  friend void f(A &);
27
  operator int();
28
  void g(A a) {
29
- int i = f(a); // f is the typedef, not the friend
30
- // function: equivalent to int(a)
31
  }
32
  };
33
  }
34
  ```
35
 
36
  Because the expression is not a function call, the argument-dependent
37
  name lookup ([[basic.lookup.argdep]]) does not apply and the friend
38
  function `f` is not found.
39
 
 
 
40
  A name used in global scope, outside of any function, class or
41
  user-declared namespace, shall be declared before its use in global
42
  scope.
43
 
44
  A name used in a user-declared namespace outside of the definition of
45
  any function or class shall be declared before its use in that namespace
46
  or before its use in a namespace enclosing its namespace.
47
 
48
- A name used in the definition of a function following the function’s
49
- *declarator-id*[^4] that is a member of namespace `N` (where, only for
50
- the purpose of exposition, `N` could represent the global scope) shall
51
- be declared before its use in the block in which it is used or in one of
52
- its enclosing blocks ([[stmt.block]]) or, shall be declared before its
53
- use in namespace `N` or, if `N` is a nested namespace, shall be declared
54
  before its use in one of `N`’s enclosing namespaces.
55
 
 
 
56
  ``` cpp
57
  namespace A {
58
  namespace N {
59
  void f();
60
  }
@@ -67,30 +72,34 @@ void A::N::f() {
67
  // 3) scope of namespace A
68
  // 4) global scope, before the definition of A::N::f
69
  }
70
  ```
71
 
 
 
72
  A name used in the definition of a class `X` outside of a member
73
- function body, default argument, *exception-specification*,
74
  *brace-or-equal-initializer* of a non-static data member, or nested
75
  class definition[^5] shall be declared in one of the following ways:
76
 
77
  - before its use in class `X` or be a member of a base class of `X` (
78
  [[class.member.lookup]]), or
79
  - if `X` is a nested class of class `Y` ([[class.nest]]), before the
80
  definition of `X` in `Y`, or shall be a member of a base class of `Y`
81
- (this lookup applies in turn to `Y` ’s enclosing classes, starting
82
- with the innermost enclosing class),[^6] or
83
  - if `X` is a local class ([[class.local]]) or is a nested class of a
84
  local class, before the definition of class `X` in a block enclosing
85
  the definition of class `X`, or
86
  - if `X` is a member of namespace `N`, or is a nested class of a class
87
  that is a member of `N`, or is a local class or a nested class within
88
  a local class of a function that is a member of `N`, before the
89
  definition of class `X` in namespace `N` or in one of `N`’s enclosing
90
  namespaces.
91
 
 
 
92
  ``` cpp
93
  namespace M {
94
  class B { };
95
  }
96
  ```
@@ -110,21 +119,25 @@ namespace N {
110
  // 3) scope of N::Y's base class M::B
111
  // 4) scope of namespace N, before the definition of N::Y
112
  // 5) global scope, before the definition of N
113
  ```
114
 
115
- When looking for a prior declaration of a class or function introduced
116
- by a `friend` declaration, scopes outside of the innermost enclosing
117
- namespace scope are not considered; see  [[namespace.memdef]].
118
- [[basic.scope.class]] further describes the restrictions on the use of
119
- names in a class definition. [[class.nest]] further describes the
120
- restrictions on the use of names in nested class definitions.
 
 
 
 
121
  [[class.local]] further describes the restrictions on the use of names
122
- in local class definitions.
123
 
124
  For the members of a class `X`, a name used in a member function body,
125
- in a default argument, in an *exception-specification*, in the
126
  *brace-or-equal-initializer* of a non-static data member (
127
  [[class.mem]]), or in the definition of a class member outside of the
128
  definition of `X`, following the member’s *declarator-id*[^7], shall be
129
  declared in one of the following ways:
130
 
@@ -142,10 +155,12 @@ declared in one of the following ways:
142
  - if `X` is a member of namespace `N`, or is a nested class of a class
143
  that is a member of `N`, or is a local class or a nested class within
144
  a local class of a function that is a member of `N`, before the use of
145
  the name, in namespace `N` or in one of `N`’s enclosing namespaces.
146
 
 
 
147
  ``` cpp
148
  class B { };
149
  namespace M {
150
  namespace N {
151
  class X : public B {
@@ -164,15 +179,18 @@ void M::N::X::f() {
164
  // 4) scope of namespace M::N
165
  // 5) scope of namespace M
166
  // 6) global scope, before the definition of M::N::X::f
167
  ```
168
 
169
- [[class.mfct]] and  [[class.static]] further describe the restrictions
170
- on the use of names in member function definitions. [[class.nest]]
171
- further describes the restrictions on the use of names in the scope of
172
- nested classes. [[class.local]] further describes the restrictions on
173
- the use of names in local class definitions.
 
 
 
174
 
175
  Name lookup for a name used in the definition of a `friend` function (
176
  [[class.friend]]) defined inline in the class granting friendship shall
177
  proceed as described for lookup in member function definitions. If the
178
  `friend` function is not defined in the class granting friendship, name
@@ -185,10 +203,12 @@ function declarator and not part of a *template-argument* in the
185
  class ([[class.member.lookup]]). If it is not found, or if the name is
186
  part of a *template-argument* in the *declarator-id*, the look up is as
187
  described for unqualified names in the definition of the class granting
188
  friendship.
189
 
 
 
190
  ``` cpp
191
  struct A {
192
  typedef int AT;
193
  void f1(AT);
194
  void f2(float);
@@ -201,36 +221,44 @@ struct B {
201
  friend void A::f2(BT); // parameter type is B::BT
202
  friend void A::f3<AT>(); // template argument is B::AT
203
  };
204
  ```
205
 
 
 
206
  During the lookup for a name used as a default argument (
207
  [[dcl.fct.default]]) in a function *parameter-declaration-clause* or
208
  used in the *expression* of a *mem-initializer* for a constructor (
209
  [[class.base.init]]), the function parameter names are visible and hide
210
  the names of entities declared in the block, class or namespace scopes
211
- containing the function declaration. [[dcl.fct.default]] further
212
- describes the restrictions on the use of names in default arguments.
213
- [[class.base.init]] further describes the restrictions on the use of
214
- names in a *ctor-initializer*.
 
 
215
 
216
  During the lookup of a name used in the *constant-expression* of an
217
  *enumerator-definition*, previously declared *enumerator*s of the
218
  enumeration are visible and hide the names of entities declared in the
219
  block, class, or namespace scopes containing the *enum-specifier*.
220
 
221
  A name used in the definition of a `static` data member of class `X` (
222
  [[class.static.data]]) (after the *qualified-id* of the static member)
223
  is looked up as if the name was used in a member function of `X`.
224
- [[class.static.data]] further describes the restrictions on the use of
225
- names in the definition of a `static` data member.
 
 
226
 
227
  If a variable member of a namespace is defined outside of the scope of
228
  its namespace then any name that appears in the definition of the member
229
  (after the *declarator-id*) is looked up as if the definition of the
230
  member occurred in its namespace.
231
 
 
 
232
  ``` cpp
233
  namespace N {
234
  int i = 4;
235
  extern int j;
236
  }
@@ -238,17 +266,20 @@ namespace N {
238
  int i = 2;
239
 
240
  int N::j = i; // N::j == 4
241
  ```
242
 
 
 
243
  A name used in the handler for a *function-try-block* (Clause 
244
  [[except]]) is looked up as if the name was used in the outermost block
245
  of the function definition. In particular, the function parameter names
246
  shall not be redeclared in the *exception-declaration* nor in the
247
  outermost block of a handler for the *function-try-block*. Names
248
  declared in the outermost block of the function definition are not found
249
  when looked up in the scope of a handler for the *function-try-block*.
250
- But function parameter names are found.
251
 
252
- The rules for name lookup in template definitions are described in 
253
- [[temp.res]].
 
 
254
 
 
11
  described in  [[basic.lookup.unqual]], the declarations from the
12
  namespace nominated by the *using-directive* are considered members of
13
  that enclosing namespace.
14
 
15
  The lookup for an unqualified name used as the *postfix-expression* of a
16
+ function call is described in  [[basic.lookup.argdep]].
17
+
18
+ [*Note 1*:
19
+
20
+ For purposes of determining (during parsing) whether an expression is a
21
  *postfix-expression* for a function call, the usual name lookup rules
22
  apply. The rules in  [[basic.lookup.argdep]] have no effect on the
23
  syntactic interpretation of an expression. For example,
24
 
25
  ``` cpp
 
27
  namespace N {
28
  struct A {
29
  friend void f(A &);
30
  operator int();
31
  void g(A a) {
32
+ int i = f(a); // f is the typedef, not the friend function: equivalent to int(a)
 
33
  }
34
  };
35
  }
36
  ```
37
 
38
  Because the expression is not a function call, the argument-dependent
39
  name lookup ([[basic.lookup.argdep]]) does not apply and the friend
40
  function `f` is not found.
41
 
42
+ — *end note*]
43
+
44
  A name used in global scope, outside of any function, class or
45
  user-declared namespace, shall be declared before its use in global
46
  scope.
47
 
48
  A name used in a user-declared namespace outside of the definition of
49
  any function or class shall be declared before its use in that namespace
50
  or before its use in a namespace enclosing its namespace.
51
 
52
+ In the definition of a function that is a member of namespace `N`, a
53
+ name used after the function’s *declarator-id*[^4] shall be declared
54
+ before its use in the block in which it is used or in one of its
55
+ enclosing blocks ([[stmt.block]]) or shall be declared before its use
56
+ in namespace `N` or, if `N` is a nested namespace, shall be declared
 
57
  before its use in one of `N`’s enclosing namespaces.
58
 
59
+ [*Example 1*:
60
+
61
  ``` cpp
62
  namespace A {
63
  namespace N {
64
  void f();
65
  }
 
72
  // 3) scope of namespace A
73
  // 4) global scope, before the definition of A::N::f
74
  }
75
  ```
76
 
77
+ — *end example*]
78
+
79
  A name used in the definition of a class `X` outside of a member
80
+ function body, default argument, *noexcept-specifier*,
81
  *brace-or-equal-initializer* of a non-static data member, or nested
82
  class definition[^5] shall be declared in one of the following ways:
83
 
84
  - before its use in class `X` or be a member of a base class of `X` (
85
  [[class.member.lookup]]), or
86
  - if `X` is a nested class of class `Y` ([[class.nest]]), before the
87
  definition of `X` in `Y`, or shall be a member of a base class of `Y`
88
+ (this lookup applies in turn to `Y`’s enclosing classes, starting with
89
+ the innermost enclosing class),[^6] or
90
  - if `X` is a local class ([[class.local]]) or is a nested class of a
91
  local class, before the definition of class `X` in a block enclosing
92
  the definition of class `X`, or
93
  - if `X` is a member of namespace `N`, or is a nested class of a class
94
  that is a member of `N`, or is a local class or a nested class within
95
  a local class of a function that is a member of `N`, before the
96
  definition of class `X` in namespace `N` or in one of `N`’s enclosing
97
  namespaces.
98
 
99
+ [*Example 2*:
100
+
101
  ``` cpp
102
  namespace M {
103
  class B { };
104
  }
105
  ```
 
119
  // 3) scope of N::Y's base class M::B
120
  // 4) scope of namespace N, before the definition of N::Y
121
  // 5) global scope, before the definition of N
122
  ```
123
 
124
+ *end example*]
125
+
126
+ [*Note 2*: When looking for a prior declaration of a class or function
127
+ introduced by a `friend` declaration, scopes outside of the innermost
128
+ enclosing namespace scope are not considered; see 
129
+ [[namespace.memdef]]. *end note*]
130
+
131
+ [*Note 3*: [[basic.scope.class]] further describes the restrictions on
132
+ the use of names in a class definition. [[class.nest]] further describes
133
+ the restrictions on the use of names in nested class definitions.
134
  [[class.local]] further describes the restrictions on the use of names
135
+ in local class definitions. — *end note*]
136
 
137
  For the members of a class `X`, a name used in a member function body,
138
+ in a default argument, in a *noexcept-specifier*, in the
139
  *brace-or-equal-initializer* of a non-static data member (
140
  [[class.mem]]), or in the definition of a class member outside of the
141
  definition of `X`, following the member’s *declarator-id*[^7], shall be
142
  declared in one of the following ways:
143
 
 
155
  - if `X` is a member of namespace `N`, or is a nested class of a class
156
  that is a member of `N`, or is a local class or a nested class within
157
  a local class of a function that is a member of `N`, before the use of
158
  the name, in namespace `N` or in one of `N`’s enclosing namespaces.
159
 
160
+ [*Example 3*:
161
+
162
  ``` cpp
163
  class B { };
164
  namespace M {
165
  namespace N {
166
  class X : public B {
 
179
  // 4) scope of namespace M::N
180
  // 5) scope of namespace M
181
  // 6) global scope, before the definition of M::N::X::f
182
  ```
183
 
184
+ *end example*]
185
+
186
+ [*Note 4*: [[class.mfct]] and  [[class.static]] further describe the
187
+ restrictions on the use of names in member function definitions.
188
+ [[class.nest]] further describes the restrictions on the use of names in
189
+ the scope of nested classes. [[class.local]] further describes the
190
+ restrictions on the use of names in local class
191
+ definitions. — *end note*]
192
 
193
  Name lookup for a name used in the definition of a `friend` function (
194
  [[class.friend]]) defined inline in the class granting friendship shall
195
  proceed as described for lookup in member function definitions. If the
196
  `friend` function is not defined in the class granting friendship, name
 
203
  class ([[class.member.lookup]]). If it is not found, or if the name is
204
  part of a *template-argument* in the *declarator-id*, the look up is as
205
  described for unqualified names in the definition of the class granting
206
  friendship.
207
 
208
+ [*Example 4*:
209
+
210
  ``` cpp
211
  struct A {
212
  typedef int AT;
213
  void f1(AT);
214
  void f2(float);
 
221
  friend void A::f2(BT); // parameter type is B::BT
222
  friend void A::f3<AT>(); // template argument is B::AT
223
  };
224
  ```
225
 
226
+ — *end example*]
227
+
228
  During the lookup for a name used as a default argument (
229
  [[dcl.fct.default]]) in a function *parameter-declaration-clause* or
230
  used in the *expression* of a *mem-initializer* for a constructor (
231
  [[class.base.init]]), the function parameter names are visible and hide
232
  the names of entities declared in the block, class or namespace scopes
233
+ containing the function declaration.
234
+
235
+ [*Note 5*: [[dcl.fct.default]] further describes the restrictions on
236
+ the use of names in default arguments. [[class.base.init]] further
237
+ describes the restrictions on the use of names in a
238
+ *ctor-initializer*. — *end note*]
239
 
240
  During the lookup of a name used in the *constant-expression* of an
241
  *enumerator-definition*, previously declared *enumerator*s of the
242
  enumeration are visible and hide the names of entities declared in the
243
  block, class, or namespace scopes containing the *enum-specifier*.
244
 
245
  A name used in the definition of a `static` data member of class `X` (
246
  [[class.static.data]]) (after the *qualified-id* of the static member)
247
  is looked up as if the name was used in a member function of `X`.
248
+
249
+ [*Note 6*: [[class.static.data]] further describes the restrictions on
250
+ the use of names in the definition of a `static` data
251
+ member. — *end note*]
252
 
253
  If a variable member of a namespace is defined outside of the scope of
254
  its namespace then any name that appears in the definition of the member
255
  (after the *declarator-id*) is looked up as if the definition of the
256
  member occurred in its namespace.
257
 
258
+ [*Example 5*:
259
+
260
  ``` cpp
261
  namespace N {
262
  int i = 4;
263
  extern int j;
264
  }
 
266
  int i = 2;
267
 
268
  int N::j = i; // N::j == 4
269
  ```
270
 
271
+ — *end example*]
272
+
273
  A name used in the handler for a *function-try-block* (Clause 
274
  [[except]]) is looked up as if the name was used in the outermost block
275
  of the function definition. In particular, the function parameter names
276
  shall not be redeclared in the *exception-declaration* nor in the
277
  outermost block of a handler for the *function-try-block*. Names
278
  declared in the outermost block of the function definition are not found
279
  when looked up in the scope of a handler for the *function-try-block*.
 
280
 
281
+ [*Note 7*: But function parameter names are found. *end note*]
282
+
283
+ [*Note 8*: The rules for name lookup in template definitions are
284
+ described in  [[temp.res]]. — *end note*]
285