From Jason Turner

[namespace.udecl]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpiy0ecdfa/{from.md → to.md} +83 -63
tmp/tmpiy0ecdfa/{from.md → to.md} RENAMED
@@ -1,24 +1,24 @@
1
- ### The `using` declaration <a id="namespace.udecl">[[namespace.udecl]]</a>
2
 
3
  ``` bnf
4
  using-declaration:
5
- 'using' using-declarator-list ';'
6
  ```
7
 
8
  ``` bnf
9
  using-declarator-list:
10
  using-declarator '...'ₒₚₜ
11
  using-declarator-list ',' using-declarator '...'ₒₚₜ
12
  ```
13
 
14
  ``` bnf
15
  using-declarator:
16
- 'typename'ₒₚₜ nested-name-specifier unqualified-id
17
  ```
18
 
19
- Each *using-declarator* in a *using-declaration* [^6] introduces a set
20
  of declarations into the declarative region in which the
21
  *using-declaration* appears. The set of declarations introduced by the
22
  *using-declarator* is found by performing qualified name lookup (
23
  [[basic.lookup.qual]], [[class.member.lookup]]) for the name in the
24
  *using-declarator*, excluding functions that are hidden as described
@@ -57,17 +57,30 @@ struct D : B {
57
  ```
58
 
59
  — *end example*]
60
 
61
  In a *using-declaration* used as a *member-declaration*, each
62
- *using-declarator*'s *nested-name-specifier* shall name a base class of
63
- the class being defined. If a *using-declarator* names a constructor,
64
- its *nested-name-specifier* shall name a direct base class of the class
65
- being defined.
66
 
67
  [*Example 2*:
68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  ``` cpp
70
  template <typename... bases>
71
  struct X : bases... {
72
  using bases::g...;
73
  };
@@ -75,11 +88,11 @@ struct X : bases... {
75
  X<B, D> x; // OK: B::g and D::g introduced
76
  ```
77
 
78
  — *end example*]
79
 
80
- [*Example 3*:
81
 
82
  ``` cpp
83
  class C {
84
  int g();
85
  };
@@ -96,45 +109,44 @@ class D2 : public B {
96
 
97
  [*Note 2*: Since destructors do not have names, a *using-declaration*
98
  cannot refer to a destructor for a base class. Since specializations of
99
  member templates for conversion functions are not found by name lookup,
100
  they are not considered when a *using-declaration* specifies a
101
- conversion function ([[temp.mem]]). — *end note*]
102
 
103
  If a constructor or assignment operator brought from a base class into a
104
  derived class has the signature of a copy/move constructor or assignment
105
- operator for the derived class ([[class.copy]]), the
106
- *using-declaration* does not by itself suppress the implicit declaration
107
- of the derived class member; the member from the base class is hidden or
108
- overridden by the implicitly-declared copy/move constructor or
109
- assignment operator of the derived class, as described below.
 
110
 
111
  A *using-declaration* shall not name a *template-id*.
112
 
113
- [*Example 4*:
114
 
115
  ``` cpp
116
  struct A {
117
  template <class T> void f(T);
118
  template <class T> struct X { };
119
  };
120
  struct B : A {
121
- using A::f<double>; // ill-formed
122
- using A::X<int>; // ill-formed
123
  };
124
  ```
125
 
126
  — *end example*]
127
 
128
  A *using-declaration* shall not name a namespace.
129
 
130
- A *using-declaration* shall not name a scoped enumerator.
 
131
 
132
- A *using-declaration* that names a class member shall be a
133
- *member-declaration*.
134
-
135
- [*Example 5*:
136
 
137
  ``` cpp
138
  struct X {
139
  int i;
140
  static int s;
@@ -147,13 +159,13 @@ void f() {
147
  ```
148
 
149
  — *end example*]
150
 
151
  Members declared by a *using-declaration* can be referred to by explicit
152
- qualification just like other member names ([[namespace.qual]]).
153
 
154
- [*Example 6*:
155
 
156
  ``` cpp
157
  void f();
158
 
159
  namespace A {
@@ -175,11 +187,11 @@ void h()
175
  — *end example*]
176
 
177
  A *using-declaration* is a *declaration* and can therefore be used
178
  repeatedly where (and only where) multiple declarations are allowed.
179
 
180
- [*Example 7*:
181
 
182
  ``` cpp
183
  namespace A {
184
  int i;
185
  }
@@ -202,15 +214,15 @@ struct X : B {
202
  [*Note 3*: For a *using-declaration* whose *nested-name-specifier*
203
  names a namespace, members added to the namespace after the
204
  *using-declaration* are not in the set of introduced declarations, so
205
  they are not considered when a use of the name is made. Thus, additional
206
  overloads added after the *using-declaration* are ignored, but default
207
- function arguments ([[dcl.fct.default]]), default template arguments (
208
- [[temp.param]]), and template specializations ([[temp.class.spec]],
209
  [[temp.expl.spec]]) are considered. — *end note*]
210
 
211
- [*Example 8*:
212
 
213
  ``` cpp
214
  namespace A {
215
  void f(int);
216
  }
@@ -235,17 +247,17 @@ void bar() {
235
  [*Note 4*: Partial specializations of class templates are found by
236
  looking up the primary class template and then considering all partial
237
  specializations of that template. If a *using-declaration* names a class
238
  template, partial specializations introduced after the
239
  *using-declaration* are effectively visible because the primary template
240
- is visible ([[temp.class.spec]]). — *end note*]
241
 
242
  Since a *using-declaration* is a declaration, the restrictions on
243
- declarations of the same name in the same declarative region (
244
- [[basic.scope]]) also apply to *using-declaration*s.
245
 
246
- [*Example 9*:
247
 
248
  ``` cpp
249
  namespace A {
250
  int x;
251
  }
@@ -276,25 +288,26 @@ void func() {
276
  ```
277
 
278
  — *end example*]
279
 
280
  If a function declaration in namespace scope or block scope has the same
281
- name and the same parameter-type-list ([[dcl.fct]]) as a function
282
  introduced by a *using-declaration*, and the declarations do not declare
283
  the same function, the program is ill-formed. If a function template
284
  declaration in namespace scope has the same name, parameter-type-list,
285
- return type, and template parameter list as a function template
286
- introduced by a *using-declaration*, the program is ill-formed.
 
287
 
288
  [*Note 5*:
289
 
290
  Two *using-declaration*s may introduce functions with the same name and
291
  the same parameter-type-list. If, for a call to an unqualified function
292
  name, function overload resolution selects the functions introduced by
293
  such *using-declaration*s, the function call is ill-formed.
294
 
295
- [*Example 10*:
296
 
297
  ``` cpp
298
  namespace B {
299
  void f(int);
300
  void f(double);
@@ -319,16 +332,17 @@ void h() {
319
  — *end note*]
320
 
321
  When a *using-declarator* brings declarations from a base class into a
322
  derived class, member functions and member function templates in the
323
  derived class override and/or hide member functions and member function
324
- templates with the same name, parameter-type-list ([[dcl.fct]]),
325
- cv-qualification, and *ref-qualifier* (if any) in a base class (rather
326
- than conflicting). Such hidden or overridden declarations are excluded
327
- from the set of declarations introduced by the *using-declarator*.
 
328
 
329
- [*Example 11*:
330
 
331
  ``` cpp
332
  struct B {
333
  virtual void f(int);
334
  virtual void f(char);
@@ -365,11 +379,11 @@ struct B2 {
365
 
366
  struct D1 : B1, B2 {
367
  using B1::B1;
368
  using B2::B2;
369
  };
370
- D1 d1(0); // ill-formed: ambiguous
371
 
372
  struct D2 : B1, B2 {
373
  using B1::B1;
374
  using B2::B2;
375
  D2(int); // OK: D2::D2(int) hides B1::B1(int) and B2::B2(int)
@@ -377,25 +391,31 @@ struct D2 : B1, B2 {
377
  D2 d2(0); // calls D2::D2(int)
378
  ```
379
 
380
  — *end example*]
381
 
382
- For the purpose of overload resolution, the functions that are
383
- introduced by a *using-declaration* into a derived class are treated as
384
- though they were members of the derived class. In particular, the
385
- implicit `this` parameter shall be treated as if it were a pointer to
386
- the derived class rather than to the base class. This has no effect on
387
- the type of the function, and in all other respects the function remains
388
- a member of the base class. Likewise, constructors that are introduced
389
- by a *using-declaration* are treated as though they were constructors of
390
- the derived class when looking up the constructors of the derived
391
- class ([[class.qual]]) or forming a set of overload candidates (
392
- [[over.match.ctor]], [[over.match.copy]], [[over.match.list]]). If such
393
- a constructor is selected to perform the initialization of an object of
394
- class type, all subobjects other than the base class from which the
395
- constructor originated are implicitly initialized (
396
- [[class.inhctor.init]]).
 
 
 
 
 
 
397
 
398
  In a *using-declarator* that does not name a constructor, all members of
399
  the set of introduced declarations shall be accessible. In a
400
  *using-declarator* that names a constructor, no access check is
401
  performed. In particular, if a derived class uses a *using-declarator*
@@ -404,18 +424,18 @@ If the name is that of an overloaded member function, then all functions
404
  named shall be accessible. The base class members mentioned by a
405
  *using-declarator* shall be visible in the scope of at least one of the
406
  direct base classes of the class where the *using-declarator* is
407
  specified.
408
 
409
- [*Note 6*:
410
 
411
  Because a *using-declarator* designates a base class member (and not a
412
  member subobject or a member function of a base class subobject), a
413
  *using-declarator* cannot be used to resolve inherited member
414
  ambiguities.
415
 
416
- [*Example 12*:
417
 
418
  ``` cpp
419
  struct A { int x(); };
420
  struct B : A { };
421
  struct C : A {
@@ -441,11 +461,11 @@ for a *member-declaration*. A *using-declarator* that names a
441
  constructor does not create a synonym; instead, the additional
442
  constructors are accessible if they would be accessible when used to
443
  construct an object of the corresponding base class, and the
444
  accessibility of the *using-declaration* is ignored.
445
 
446
- [*Example 13*:
447
 
448
  ``` cpp
449
  class A {
450
  private:
451
  void f(char);
@@ -463,8 +483,8 @@ public:
463
  ```
464
 
465
  — *end example*]
466
 
467
  If a *using-declarator* uses the keyword `typename` and specifies a
468
- dependent name ([[temp.dep]]), the name introduced by the
469
- *using-declaration* is treated as a *typedef-name* ([[dcl.typedef]]).
470
 
 
1
+ ## The `using` declaration <a id="namespace.udecl">[[namespace.udecl]]</a>
2
 
3
  ``` bnf
4
  using-declaration:
5
+ using using-declarator-list ';'
6
  ```
7
 
8
  ``` bnf
9
  using-declarator-list:
10
  using-declarator '...'ₒₚₜ
11
  using-declarator-list ',' using-declarator '...'ₒₚₜ
12
  ```
13
 
14
  ``` bnf
15
  using-declarator:
16
+ typenameₒₚₜ nested-name-specifier unqualified-id
17
  ```
18
 
19
+ Each *using-declarator* in a *using-declaration* [^12] introduces a set
20
  of declarations into the declarative region in which the
21
  *using-declaration* appears. The set of declarations introduced by the
22
  *using-declarator* is found by performing qualified name lookup (
23
  [[basic.lookup.qual]], [[class.member.lookup]]) for the name in the
24
  *using-declarator*, excluding functions that are hidden as described
 
57
  ```
58
 
59
  — *end example*]
60
 
61
  In a *using-declaration* used as a *member-declaration*, each
62
+ *using-declarator* shall either name an enumerator or have a
63
+ *nested-name-specifier* naming a base class of the class being defined.
 
 
64
 
65
  [*Example 2*:
66
 
67
+ ``` cpp
68
+ enum class button { up, down };
69
+ struct S {
70
+ using button::up;
71
+ button b = up; // OK
72
+ };
73
+ ```
74
+
75
+ — *end example*]
76
+
77
+ If a *using-declarator* names a constructor, its *nested-name-specifier*
78
+ shall name a direct base class of the class being defined.
79
+
80
+ [*Example 3*:
81
+
82
  ``` cpp
83
  template <typename... bases>
84
  struct X : bases... {
85
  using bases::g...;
86
  };
 
88
  X<B, D> x; // OK: B::g and D::g introduced
89
  ```
90
 
91
  — *end example*]
92
 
93
+ [*Example 4*:
94
 
95
  ``` cpp
96
  class C {
97
  int g();
98
  };
 
109
 
110
  [*Note 2*: Since destructors do not have names, a *using-declaration*
111
  cannot refer to a destructor for a base class. Since specializations of
112
  member templates for conversion functions are not found by name lookup,
113
  they are not considered when a *using-declaration* specifies a
114
+ conversion function [[temp.mem]]. — *end note*]
115
 
116
  If a constructor or assignment operator brought from a base class into a
117
  derived class has the signature of a copy/move constructor or assignment
118
+ operator for the derived class ([[class.copy.ctor]],
119
+ [[class.copy.assign]]), the *using-declaration* does not by itself
120
+ suppress the implicit declaration of the derived class member; the
121
+ member from the base class is hidden or overridden by the
122
+ implicitly-declared copy/move constructor or assignment operator of the
123
+ derived class, as described below.
124
 
125
  A *using-declaration* shall not name a *template-id*.
126
 
127
+ [*Example 5*:
128
 
129
  ``` cpp
130
  struct A {
131
  template <class T> void f(T);
132
  template <class T> struct X { };
133
  };
134
  struct B : A {
135
+ using A::f<double>; // error
136
+ using A::X<int>; // error
137
  };
138
  ```
139
 
140
  — *end example*]
141
 
142
  A *using-declaration* shall not name a namespace.
143
 
144
+ A *using-declaration* that names a class member other than an enumerator
145
+ shall be a *member-declaration*.
146
 
147
+ [*Example 6*:
 
 
 
148
 
149
  ``` cpp
150
  struct X {
151
  int i;
152
  static int s;
 
159
  ```
160
 
161
  — *end example*]
162
 
163
  Members declared by a *using-declaration* can be referred to by explicit
164
+ qualification just like other member names [[namespace.qual]].
165
 
166
+ [*Example 7*:
167
 
168
  ``` cpp
169
  void f();
170
 
171
  namespace A {
 
187
  — *end example*]
188
 
189
  A *using-declaration* is a *declaration* and can therefore be used
190
  repeatedly where (and only where) multiple declarations are allowed.
191
 
192
+ [*Example 8*:
193
 
194
  ``` cpp
195
  namespace A {
196
  int i;
197
  }
 
214
  [*Note 3*: For a *using-declaration* whose *nested-name-specifier*
215
  names a namespace, members added to the namespace after the
216
  *using-declaration* are not in the set of introduced declarations, so
217
  they are not considered when a use of the name is made. Thus, additional
218
  overloads added after the *using-declaration* are ignored, but default
219
+ function arguments [[dcl.fct.default]], default template arguments
220
+ [[temp.param]], and template specializations ([[temp.class.spec]],
221
  [[temp.expl.spec]]) are considered. — *end note*]
222
 
223
+ [*Example 9*:
224
 
225
  ``` cpp
226
  namespace A {
227
  void f(int);
228
  }
 
247
  [*Note 4*: Partial specializations of class templates are found by
248
  looking up the primary class template and then considering all partial
249
  specializations of that template. If a *using-declaration* names a class
250
  template, partial specializations introduced after the
251
  *using-declaration* are effectively visible because the primary template
252
+ is visible [[temp.class.spec]]. — *end note*]
253
 
254
  Since a *using-declaration* is a declaration, the restrictions on
255
+ declarations of the same name in the same declarative region
256
+ [[basic.scope]] also apply to *using-declaration*s.
257
 
258
+ [*Example 10*:
259
 
260
  ``` cpp
261
  namespace A {
262
  int x;
263
  }
 
288
  ```
289
 
290
  — *end example*]
291
 
292
  If a function declaration in namespace scope or block scope has the same
293
+ name and the same parameter-type-list [[dcl.fct]] as a function
294
  introduced by a *using-declaration*, and the declarations do not declare
295
  the same function, the program is ill-formed. If a function template
296
  declaration in namespace scope has the same name, parameter-type-list,
297
+ trailing *requires-clause* (if any), return type, and *template-head*,
298
+ as a function template introduced by a *using-declaration*, the program
299
+ is ill-formed.
300
 
301
  [*Note 5*:
302
 
303
  Two *using-declaration*s may introduce functions with the same name and
304
  the same parameter-type-list. If, for a call to an unqualified function
305
  name, function overload resolution selects the functions introduced by
306
  such *using-declaration*s, the function call is ill-formed.
307
 
308
+ [*Example 11*:
309
 
310
  ``` cpp
311
  namespace B {
312
  void f(int);
313
  void f(double);
 
332
  — *end note*]
333
 
334
  When a *using-declarator* brings declarations from a base class into a
335
  derived class, member functions and member function templates in the
336
  derived class override and/or hide member functions and member function
337
+ templates with the same name, parameter-type-list [[dcl.fct]], trailing
338
+ *requires-clause* (if any), cv-qualification, and *ref-qualifier* (if
339
+ any), in a base class (rather than conflicting). Such hidden or
340
+ overridden declarations are excluded from the set of declarations
341
+ introduced by the *using-declarator*.
342
 
343
+ [*Example 12*:
344
 
345
  ``` cpp
346
  struct B {
347
  virtual void f(int);
348
  virtual void f(char);
 
379
 
380
  struct D1 : B1, B2 {
381
  using B1::B1;
382
  using B2::B2;
383
  };
384
+ D1 d1(0); // error: ambiguous
385
 
386
  struct D2 : B1, B2 {
387
  using B1::B1;
388
  using B2::B2;
389
  D2(int); // OK: D2::D2(int) hides B1::B1(int) and B2::B2(int)
 
391
  D2 d2(0); // calls D2::D2(int)
392
  ```
393
 
394
  — *end example*]
395
 
396
+ [*Note 6*: For the purpose of forming a set of candidates during
397
+ overload resolution, the functions that are introduced by a
398
+ *using-declaration* into a derived class are treated as though they were
399
+ members of the derived class [[class.member.lookup]]. In particular, the
400
+ implicit object parameter is treated as if it were a reference to the
401
+ derived class rather than to the base class [[over.match.funcs]]. This
402
+ has no effect on the type of the function, and in all other respects the
403
+ function remains a member of the base class. *end note*]
404
+
405
+ Constructors that are introduced by a *using-declaration* are treated as
406
+ though they were constructors of the derived class when looking up the
407
+ constructors of the derived class [[class.qual]] or forming a set of
408
+ overload candidates ([[over.match.ctor]], [[over.match.copy]],
409
+ [[over.match.list]]).
410
+
411
+ [*Note 7*: If such a constructor is selected to perform the
412
+ initialization of an object of class type, all subobjects other than the
413
+ base class from which the constructor originated are implicitly
414
+ initialized [[class.inhctor.init]]. A constructor of a derived class is
415
+ sometimes preferred to a constructor of a base class if they would
416
+ otherwise be ambiguous [[over.match.best]]. — *end note*]
417
 
418
  In a *using-declarator* that does not name a constructor, all members of
419
  the set of introduced declarations shall be accessible. In a
420
  *using-declarator* that names a constructor, no access check is
421
  performed. In particular, if a derived class uses a *using-declarator*
 
424
  named shall be accessible. The base class members mentioned by a
425
  *using-declarator* shall be visible in the scope of at least one of the
426
  direct base classes of the class where the *using-declarator* is
427
  specified.
428
 
429
+ [*Note 8*:
430
 
431
  Because a *using-declarator* designates a base class member (and not a
432
  member subobject or a member function of a base class subobject), a
433
  *using-declarator* cannot be used to resolve inherited member
434
  ambiguities.
435
 
436
+ [*Example 13*:
437
 
438
  ``` cpp
439
  struct A { int x(); };
440
  struct B : A { };
441
  struct C : A {
 
461
  constructor does not create a synonym; instead, the additional
462
  constructors are accessible if they would be accessible when used to
463
  construct an object of the corresponding base class, and the
464
  accessibility of the *using-declaration* is ignored.
465
 
466
+ [*Example 14*:
467
 
468
  ``` cpp
469
  class A {
470
  private:
471
  void f(char);
 
483
  ```
484
 
485
  — *end example*]
486
 
487
  If a *using-declarator* uses the keyword `typename` and specifies a
488
+ dependent name [[temp.dep]], the name introduced by the
489
+ *using-declaration* is treated as a *typedef-name* [[dcl.typedef]].
490