From Jason Turner

[basic.lookup.qual]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp_tsy78t9/{from.md → to.md} +43 -45
tmp/tmp_tsy78t9/{from.md → to.md} RENAMED
@@ -1,10 +1,10 @@
1
  ### Qualified name lookup <a id="basic.lookup.qual">[[basic.lookup.qual]]</a>
2
 
3
  The name of a class or namespace member or enumerator can be referred to
4
- after the `::` scope resolution operator ([[expr.prim]]) applied to a
5
- *nested-name-specifier* that denotes its class, namespace, or
6
  enumeration. If a `::` scope resolution operator in a
7
  *nested-name-specifier* is not preceded by a *decltype-specifier*,
8
  lookup of the name preceding that `::` considers only namespaces, types,
9
  and templates whose specializations are types. If the name found does
10
  not designate a namespace or a class, enumeration, or dependent type,
@@ -18,19 +18,19 @@ public:
18
  static int n;
19
  };
20
  int main() {
21
  int A;
22
  A::n = 42; // OK
23
- A b; // ill-formed: A does not name a type
24
  }
25
  ```
26
 
27
  — *end example*]
28
 
29
  [*Note 1*: Multiply qualified names, such as `N1::N2::N3::n`, can be
30
- used to refer to members of nested classes ([[class.nest]]) or members
31
- of nested namespaces. — *end note*]
32
 
33
  In a declaration in which the *declarator-id* is a *qualified-id*, names
34
  used before the *qualified-id* being declared are looked up in the
35
  defining namespace scope; names following the *qualified-id* are looked
36
  up in the scope of the member’s class or namespace.
@@ -42,38 +42,35 @@ class X { };
42
  class C {
43
  class X { };
44
  static const int number = 50;
45
  static X arr[number];
46
  };
47
- X C::arr[number]; // ill-formed:
48
  // equivalent to ::X C::arr[C::number];
49
  // and not to C::X C::arr[C::number];
50
  ```
51
 
52
  — *end example*]
53
 
54
- A name prefixed by the unary scope operator `::` ([[expr.prim]]) is
55
- looked up in global scope, in the translation unit where it is used. The
56
- name shall be declared in global namespace scope or shall be a name
57
  whose declaration is visible in global scope because of a
58
- *using-directive* ([[namespace.qual]]). The use of `::` allows a global
59
- name to be referred to even if its identifier has been hidden (
60
- [[basic.scope.hiding]]).
61
 
62
  A name prefixed by a *nested-name-specifier* that nominates an
63
  enumeration type shall represent an *enumerator* of that enumeration.
64
 
65
- If a *pseudo-destructor-name* ([[expr.pseudo]]) contains a
66
- *nested-name-specifier*, the *type-name*s are looked up as types in the
67
- scope designated by the *nested-name-specifier*. Similarly, in a
68
- *qualified-id* of the form:
69
 
70
  ``` bnf
71
- nested-name-specifierₒₚₜ class-name '::' '~' class-name
72
  ```
73
 
74
- the second *class-name* is looked up in the same scope as the first.
75
 
76
  [*Example 3*:
77
 
78
  ``` cpp
79
  struct C {
@@ -102,40 +99,39 @@ proceeds after the `.` and `->` operators. — *end note*]
102
 
103
  #### Class members <a id="class.qual">[[class.qual]]</a>
104
 
105
  If the *nested-name-specifier* of a *qualified-id* nominates a class,
106
  the name specified after the *nested-name-specifier* is looked up in the
107
- scope of the class ([[class.member.lookup]]), except for the cases
108
- listed below. The name shall represent one or more members of that class
109
- or of one of its base classes (Clause  [[class.derived]]).
110
 
111
  [*Note 1*: A class member can be referred to using a *qualified-id* at
112
- any point in its potential scope (
113
- [[basic.scope.class]]). — *end note*]
114
 
115
  The exceptions to the name lookup rule above are the following:
116
 
117
  - the lookup for a destructor is as specified in  [[basic.lookup.qual]];
118
  - a *conversion-type-id* of a *conversion-function-id* is looked up in
119
  the same manner as a *conversion-type-id* in a class member access
120
  (see  [[basic.lookup.classref]]);
121
  - the names in a *template-argument* of a *template-id* are looked up in
122
- the context in which the entire *postfix-expression* occurs.
123
- - the lookup for a name specified in a *using-declaration* (
124
- [[namespace.udecl]]) also finds class or enumeration names hidden
125
- within the same scope ([[basic.scope.hiding]]).
126
 
127
- In a lookup in which function names are not ignored[^9] and the
128
  *nested-name-specifier* nominates a class `C`:
129
 
130
  - if the name specified after the *nested-name-specifier*, when looked
131
- up in `C`, is the injected-class-name of `C` (Clause  [[class]]), or
132
- - in a *using-declarator* of a *using-declaration* (
133
- [[namespace.udecl]]) that is a *member-declaration*, if the name
134
- specified after the *nested-name-specifier* is the same as the
135
- *identifier* or the *simple-template-id*’s *template-name* in the last
136
- component of the *nested-name-specifier*,
137
 
138
  the name is instead considered to name the constructor of class `C`.
139
 
140
  [*Note 2*: For example, the constructor is not an acceptable lookup
141
  result in an *elaborated-type-specifier* so the constructor would not be
@@ -152,11 +148,11 @@ struct B: public A { B(); };
152
 
153
  A::A() { }
154
  B::B() { }
155
 
156
  B::A ba; // object of type A
157
- A::A a; // error, A::A is not a type name
158
  struct A::A a2; // object of type A
159
  ```
160
 
161
  — *end example*]
162
 
@@ -173,22 +169,24 @@ nominating the global namespace), the name specified after the
173
  names in a *template-argument* of a *template-id* are looked up in the
174
  context in which the entire *postfix-expression* occurs.
175
 
176
  For a namespace `X` and name `m`, the namespace-qualified lookup set
177
  S(X, m) is defined as follows: Let S'(X, m) be the set of all
178
- declarations of `m` in `X` and the inline namespace set of `X` (
179
- [[namespace.def]]). If S'(X, m) is not empty, S(X, m) is S'(X, m);
 
 
180
  otherwise, S(X, m) is the union of S(Nᵢ, m) for all namespaces Nᵢ
181
  nominated by *using-directive*s in `X` and its inline namespace set.
182
 
183
  Given `X::m` (where `X` is a user-declared namespace), or given `::m`
184
  (where X is the global namespace), if S(X, m) is the empty set, the
185
  program is ill-formed. Otherwise, if S(X, m) has exactly one member, or
186
- if the context of the reference is a *using-declaration* (
187
- [[namespace.udecl]]), S(X, m) is the required set of declarations of
188
- `m`. Otherwise if the use of `m` is not one that allows a unique
189
- declaration to be chosen from S(X, m), the program is ill-formed.
190
 
191
  [*Example 1*:
192
 
193
  ``` cpp
194
  int x;
@@ -324,11 +322,11 @@ void f()
324
  — *end example*]
325
 
326
  During the lookup of a qualified namespace member name, if the lookup
327
  finds more than one declaration of the member, and if one declaration
328
  introduces a class name or enumeration name and the other declarations
329
- either introduce the same variable, the same enumerator or a set of
330
  functions, the non-type name hides the class or enumeration name if and
331
  only if the declarations are from the same namespace; otherwise (the
332
  declarations are from different namespaces), the program is ill-formed.
333
 
334
  [*Example 4*:
@@ -361,23 +359,23 @@ has the form
361
  ``` bnf
362
  nested-name-specifier unqualified-id
363
  ```
364
 
365
  the *unqualified-id* shall name a member of the namespace designated by
366
- the *nested-name-specifier* or of an element of the inline namespace
367
- set ([[namespace.def]]) of that namespace.
368
 
369
  [*Example 5*:
370
 
371
  ``` cpp
372
  namespace A {
373
  namespace B {
374
  void f1(int);
375
  }
376
  using namespace B;
377
  }
378
- void A::f1(int){ } // ill-formed, f1 is not a member of A
379
  ```
380
 
381
  — *end example*]
382
 
383
  However, in such namespace member declarations, the
 
1
  ### Qualified name lookup <a id="basic.lookup.qual">[[basic.lookup.qual]]</a>
2
 
3
  The name of a class or namespace member or enumerator can be referred to
4
+ after the `::` scope resolution operator [[expr.prim.id.qual]] applied
5
+ to a *nested-name-specifier* that denotes its class, namespace, or
6
  enumeration. If a `::` scope resolution operator in a
7
  *nested-name-specifier* is not preceded by a *decltype-specifier*,
8
  lookup of the name preceding that `::` considers only namespaces, types,
9
  and templates whose specializations are types. If the name found does
10
  not designate a namespace or a class, enumeration, or dependent type,
 
18
  static int n;
19
  };
20
  int main() {
21
  int A;
22
  A::n = 42; // OK
23
+ A b; // error: A does not name a type
24
  }
25
  ```
26
 
27
  — *end example*]
28
 
29
  [*Note 1*: Multiply qualified names, such as `N1::N2::N3::n`, can be
30
+ used to refer to members of nested classes [[class.nest]] or members of
31
+ nested namespaces. — *end note*]
32
 
33
  In a declaration in which the *declarator-id* is a *qualified-id*, names
34
  used before the *qualified-id* being declared are looked up in the
35
  defining namespace scope; names following the *qualified-id* are looked
36
  up in the scope of the member’s class or namespace.
 
42
  class C {
43
  class X { };
44
  static const int number = 50;
45
  static X arr[number];
46
  };
47
+ X C::arr[number]; // error:
48
  // equivalent to ::X C::arr[C::number];
49
  // and not to C::X C::arr[C::number];
50
  ```
51
 
52
  — *end example*]
53
 
54
+ A name prefixed by the unary scope operator `::` [[expr.prim.id.qual]]
55
+ is looked up in global scope, in the translation unit where it is used.
56
+ The name shall be declared in global namespace scope or shall be a name
57
  whose declaration is visible in global scope because of a
58
+ *using-directive* [[namespace.qual]]. The use of `::` allows a global
59
+ name to be referred to even if its identifier has been hidden
60
+ [[basic.scope.hiding]].
61
 
62
  A name prefixed by a *nested-name-specifier* that nominates an
63
  enumeration type shall represent an *enumerator* of that enumeration.
64
 
65
+ In a *qualified-id* of the form:
 
 
 
66
 
67
  ``` bnf
68
+ nested-name-specifierₒₚₜ type-name '::' '~' type-name
69
  ```
70
 
71
+ the second *type-name* is looked up in the same scope as the first.
72
 
73
  [*Example 3*:
74
 
75
  ``` cpp
76
  struct C {
 
99
 
100
  #### Class members <a id="class.qual">[[class.qual]]</a>
101
 
102
  If the *nested-name-specifier* of a *qualified-id* nominates a class,
103
  the name specified after the *nested-name-specifier* is looked up in the
104
+ scope of the class [[class.member.lookup]], except for the cases listed
105
+ below. The name shall represent one or more members of that class or of
106
+ one of its base classes [[class.derived]].
107
 
108
  [*Note 1*: A class member can be referred to using a *qualified-id* at
109
+ any point in its potential scope [[basic.scope.class]]. — *end note*]
 
110
 
111
  The exceptions to the name lookup rule above are the following:
112
 
113
  - the lookup for a destructor is as specified in  [[basic.lookup.qual]];
114
  - a *conversion-type-id* of a *conversion-function-id* is looked up in
115
  the same manner as a *conversion-type-id* in a class member access
116
  (see  [[basic.lookup.classref]]);
117
  - the names in a *template-argument* of a *template-id* are looked up in
118
+ the context in which the entire *postfix-expression* occurs;
119
+ - the lookup for a name specified in a *using-declaration*
120
+ [[namespace.udecl]] also finds class or enumeration names hidden
121
+ within the same scope [[basic.scope.hiding]].
122
 
123
+ In a lookup in which function names are not ignored[^8] and the
124
  *nested-name-specifier* nominates a class `C`:
125
 
126
  - if the name specified after the *nested-name-specifier*, when looked
127
+ up in `C`, is the injected-class-name of `C` [[class.pre]], or
128
+ - in a *using-declarator* of a *using-declaration* [[namespace.udecl]]
129
+ that is a *member-declaration*, if the name specified after the
130
+ *nested-name-specifier* is the same as the *identifier* or the
131
+ *simple-template-id*’s *template-name* in the last component of the
132
+ *nested-name-specifier*,
133
 
134
  the name is instead considered to name the constructor of class `C`.
135
 
136
  [*Note 2*: For example, the constructor is not an acceptable lookup
137
  result in an *elaborated-type-specifier* so the constructor would not be
 
148
 
149
  A::A() { }
150
  B::B() { }
151
 
152
  B::A ba; // object of type A
153
+ A::A a; // error: A::A is not a type name
154
  struct A::A a2; // object of type A
155
  ```
156
 
157
  — *end example*]
158
 
 
169
  names in a *template-argument* of a *template-id* are looked up in the
170
  context in which the entire *postfix-expression* occurs.
171
 
172
  For a namespace `X` and name `m`, the namespace-qualified lookup set
173
  S(X, m) is defined as follows: Let S'(X, m) be the set of all
174
+ declarations of `m` in `X` and the inline namespace set of `X`
175
+ [[namespace.def]] whose potential scope [[basic.scope.namespace]] would
176
+ include the namespace in which `m` is declared at the location of the
177
+ *nested-name-specifier*. If S'(X, m) is not empty, S(X, m) is S'(X, m);
178
  otherwise, S(X, m) is the union of S(Nᵢ, m) for all namespaces Nᵢ
179
  nominated by *using-directive*s in `X` and its inline namespace set.
180
 
181
  Given `X::m` (where `X` is a user-declared namespace), or given `::m`
182
  (where X is the global namespace), if S(X, m) is the empty set, the
183
  program is ill-formed. Otherwise, if S(X, m) has exactly one member, or
184
+ if the context of the reference is a *using-declaration*
185
+ [[namespace.udecl]], S(X, m) is the required set of declarations of `m`.
186
+ Otherwise if the use of `m` is not one that allows a unique declaration
187
+ to be chosen from S(X, m), the program is ill-formed.
188
 
189
  [*Example 1*:
190
 
191
  ``` cpp
192
  int x;
 
322
  — *end example*]
323
 
324
  During the lookup of a qualified namespace member name, if the lookup
325
  finds more than one declaration of the member, and if one declaration
326
  introduces a class name or enumeration name and the other declarations
327
+ introduce either the same variable, the same enumerator, or a set of
328
  functions, the non-type name hides the class or enumeration name if and
329
  only if the declarations are from the same namespace; otherwise (the
330
  declarations are from different namespaces), the program is ill-formed.
331
 
332
  [*Example 4*:
 
359
  ``` bnf
360
  nested-name-specifier unqualified-id
361
  ```
362
 
363
  the *unqualified-id* shall name a member of the namespace designated by
364
+ the *nested-name-specifier* or of an element of the inline namespace set
365
+ [[namespace.def]] of that namespace.
366
 
367
  [*Example 5*:
368
 
369
  ``` cpp
370
  namespace A {
371
  namespace B {
372
  void f1(int);
373
  }
374
  using namespace B;
375
  }
376
+ void A::f1(int){ } // error: f1 is not a member of A
377
  ```
378
 
379
  — *end example*]
380
 
381
  However, in such namespace member declarations, the