- tmp/tmp_3ovezy8/{from.md → to.md} +120 -234
tmp/tmp_3ovezy8/{from.md → to.md}
RENAMED
|
@@ -14,57 +14,43 @@ using-declarator-list:
|
|
| 14 |
``` bnf
|
| 15 |
using-declarator:
|
| 16 |
typenameₒₚₜ nested-name-specifier unqualified-id
|
| 17 |
```
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
*using-declaration*
|
| 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
|
| 25 |
-
below. If the *using-declarator* does not name a constructor, the
|
| 26 |
-
*unqualified-id* is declared in the declarative region in which the
|
| 27 |
-
*using-declaration* appears as a synonym for each declaration introduced
|
| 28 |
-
by the *using-declarator*.
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
If the *using-declarator* names a constructor, it declares that the
|
| 36 |
-
class *inherits* the set of constructor declarations
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
``` cpp
|
| 45 |
-
struct B {
|
| 46 |
-
void f(char);
|
| 47 |
-
void g(char);
|
| 48 |
-
enum E { e };
|
| 49 |
-
union { int x; };
|
| 50 |
-
};
|
| 51 |
-
|
| 52 |
-
struct D : B {
|
| 53 |
-
using B::f;
|
| 54 |
-
void f(int) { f('c'); } // calls B::f(char)
|
| 55 |
-
void g(int) { g('c'); } // recursively calls D::g(int)
|
| 56 |
-
};
|
| 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
|
|
|
|
| 64 |
|
| 65 |
-
[*Example
|
| 66 |
|
| 67 |
``` cpp
|
| 68 |
enum class button { up, down };
|
| 69 |
struct S {
|
| 70 |
using button::up;
|
|
@@ -73,60 +59,59 @@ struct S {
|
|
| 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
|
|
|
|
|
|
|
| 79 |
|
| 80 |
-
[*Example
|
| 81 |
|
| 82 |
``` cpp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
template <typename... bases>
|
| 84 |
struct X : bases... {
|
| 85 |
-
using bases::
|
| 86 |
-
};
|
| 87 |
-
|
| 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 |
-
};
|
| 99 |
-
|
| 100 |
-
class D2 : public B {
|
| 101 |
-
using B::f; // OK: B is a base of D2
|
| 102 |
-
using B::e; // OK: e is an enumerator of base B
|
| 103 |
-
using B::x; // OK: x is a union member of base B
|
| 104 |
-
using C::g; // error: C isn't a base of D2
|
| 105 |
};
|
|
|
|
| 106 |
```
|
| 107 |
|
| 108 |
— *end example*]
|
| 109 |
|
| 110 |
[*Note 2*: Since destructors do not have names, a *using-declaration*
|
| 111 |
-
cannot refer to a destructor for a base class.
|
| 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
|
| 119 |
-
[[class.copy.assign]]
|
| 120 |
-
suppress the implicit declaration of the derived class
|
| 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
|
| 128 |
|
| 129 |
``` cpp
|
| 130 |
struct A {
|
| 131 |
template <class T> void f(T);
|
| 132 |
template <class T> struct X { };
|
|
@@ -142,11 +127,11 @@ struct B : A {
|
|
| 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
|
| 148 |
|
| 149 |
``` cpp
|
| 150 |
struct X {
|
| 151 |
int i;
|
| 152 |
static int s;
|
|
@@ -158,71 +143,21 @@ void f() {
|
|
| 158 |
}
|
| 159 |
```
|
| 160 |
|
| 161 |
— *end example*]
|
| 162 |
|
| 163 |
-
|
| 164 |
-
|
| 165 |
|
| 166 |
-
[*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
|
| 168 |
-
|
| 169 |
-
void f();
|
| 170 |
-
|
| 171 |
-
namespace A {
|
| 172 |
-
void g();
|
| 173 |
-
}
|
| 174 |
-
|
| 175 |
-
namespace X {
|
| 176 |
-
using ::f; // global f
|
| 177 |
-
using A::g; // A's g
|
| 178 |
-
}
|
| 179 |
-
|
| 180 |
-
void h()
|
| 181 |
-
{
|
| 182 |
-
X::f(); // calls ::f
|
| 183 |
-
X::g(); // calls A::g
|
| 184 |
-
}
|
| 185 |
-
```
|
| 186 |
-
|
| 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 |
-
}
|
| 198 |
-
|
| 199 |
-
namespace A1 {
|
| 200 |
-
using A::i, A::i; // OK: double declaration
|
| 201 |
-
}
|
| 202 |
-
|
| 203 |
-
struct B {
|
| 204 |
-
int i;
|
| 205 |
-
};
|
| 206 |
-
|
| 207 |
-
struct X : B {
|
| 208 |
-
using B::i, B::i; // error: double member declaration
|
| 209 |
-
};
|
| 210 |
-
```
|
| 211 |
-
|
| 212 |
-
— *end example*]
|
| 213 |
-
|
| 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 |
}
|
|
@@ -242,107 +177,70 @@ void bar() {
|
|
| 242 |
}
|
| 243 |
```
|
| 244 |
|
| 245 |
— *end example*]
|
| 246 |
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
|
|
|
| 253 |
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
[[basic.scope]] also apply to *using-declaration*s.
|
| 257 |
|
| 258 |
-
[*Example
|
| 259 |
|
| 260 |
``` cpp
|
| 261 |
namespace A {
|
| 262 |
int x;
|
|
|
|
|
|
|
|
|
|
| 263 |
}
|
| 264 |
|
| 265 |
namespace B {
|
| 266 |
int i;
|
| 267 |
struct g { };
|
| 268 |
struct x { };
|
| 269 |
void f(int);
|
| 270 |
void f(double);
|
| 271 |
-
void g(char);
|
| 272 |
}
|
| 273 |
|
| 274 |
void func() {
|
| 275 |
int i;
|
| 276 |
-
using B::i;
|
| 277 |
void f(char);
|
| 278 |
-
using B::f;
|
|
|
|
|
|
|
|
|
|
| 279 |
f(3.5); // calls B::f(double)
|
| 280 |
using B::g;
|
| 281 |
g('a'); // calls B::g(char)
|
| 282 |
struct g g1; // g1 has class type B::g
|
|
|
|
|
|
|
|
|
|
| 283 |
using B::x;
|
| 284 |
-
using A::x;
|
| 285 |
x = 99; // assigns to A::x
|
| 286 |
struct x x1; // x1 has class type B::x
|
| 287 |
}
|
| 288 |
```
|
| 289 |
|
| 290 |
— *end example*]
|
| 291 |
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 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 |
-
[*
|
| 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);
|
| 314 |
-
}
|
| 315 |
-
namespace C {
|
| 316 |
-
void f(int);
|
| 317 |
-
void f(double);
|
| 318 |
-
void f(char);
|
| 319 |
-
}
|
| 320 |
-
|
| 321 |
-
void h() {
|
| 322 |
-
using B::f; // B::f(int) and B::f(double)
|
| 323 |
-
using C::f; // C::f(int), C::f(double), and C::f(char)
|
| 324 |
-
f('h'); // calls C::f(char)
|
| 325 |
-
f(1); // error: ambiguous: B::f(int) or C::f(int)?
|
| 326 |
-
void f(int); // error: f(int) conflicts with C::f(int) and B::f(int)
|
| 327 |
-
}
|
| 328 |
-
```
|
| 329 |
-
|
| 330 |
-
— *end example*]
|
| 331 |
-
|
| 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);
|
|
@@ -350,17 +248,17 @@ struct B {
|
|
| 350 |
void h(int);
|
| 351 |
};
|
| 352 |
|
| 353 |
struct D : B {
|
| 354 |
using B::f;
|
| 355 |
-
void f(int); // OK
|
| 356 |
|
| 357 |
using B::g;
|
| 358 |
void g(char); // OK
|
| 359 |
|
| 360 |
using B::h;
|
| 361 |
-
void h(int); // OK
|
| 362 |
};
|
| 363 |
|
| 364 |
void k(D* p)
|
| 365 |
{
|
| 366 |
p->f(1); // calls D::f(int)
|
|
@@ -384,58 +282,51 @@ struct D1 : B1, B2 {
|
|
| 384 |
D1 d1(0); // error: ambiguous
|
| 385 |
|
| 386 |
struct D2 : B1, B2 {
|
| 387 |
using B1::B1;
|
| 388 |
using B2::B2;
|
| 389 |
-
D2(int); // OK
|
| 390 |
};
|
| 391 |
D2 d2(0); // calls D2::D2(int)
|
| 392 |
```
|
| 393 |
|
| 394 |
— *end example*]
|
| 395 |
|
| 396 |
-
[*Note
|
| 397 |
-
overload resolution, the functions
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
|
| 405 |
-
Constructors that are
|
| 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
|
| 409 |
-
[[over.match.list]]
|
| 410 |
|
| 411 |
-
[*Note
|
| 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,
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
performed. In particular, if a derived class uses a *using-declarator*
|
| 422 |
-
to access a member of a base class, the member name shall be accessible.
|
| 423 |
-
If the name is that of an overloaded member function, then all functions
|
| 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
|
| 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
|
| 437 |
|
| 438 |
``` cpp
|
| 439 |
struct A { int x(); };
|
| 440 |
struct B : A { };
|
| 441 |
struct C : A {
|
|
@@ -454,18 +345,17 @@ int f(D* d) {
|
|
| 454 |
|
| 455 |
— *end example*]
|
| 456 |
|
| 457 |
— *end note*]
|
| 458 |
|
| 459 |
-
A
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
accessibility of the *using-declaration* is ignored.
|
| 465 |
|
| 466 |
-
[*Example
|
| 467 |
|
| 468 |
``` cpp
|
| 469 |
class A {
|
| 470 |
private:
|
| 471 |
void f(char);
|
|
@@ -482,9 +372,5 @@ public:
|
|
| 482 |
};
|
| 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 |
-
|
|
|
|
| 14 |
``` bnf
|
| 15 |
using-declarator:
|
| 16 |
typenameₒₚₜ nested-name-specifier unqualified-id
|
| 17 |
```
|
| 18 |
|
| 19 |
+
The component names of a *using-declarator* are those of its
|
| 20 |
+
*nested-name-specifier* and *unqualified-id*. Each *using-declarator* in
|
| 21 |
+
a *using-declaration*[^11]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
names the set of declarations found by lookup [[basic.lookup.qual]] for
|
| 24 |
+
the *using-declarator*, except that class and enumeration declarations
|
| 25 |
+
that would be discarded are merely ignored when checking for ambiguity
|
| 26 |
+
[[basic.lookup]], conversion function templates with a dependent return
|
| 27 |
+
type are ignored, and certain functions are hidden as described below.
|
| 28 |
+
If the terminal name of the *using-declarator* is dependent
|
| 29 |
+
[[temp.dep.type]], the *using-declarator* is considered to name a
|
| 30 |
+
constructor if and only if the *nested-name-specifier* has a terminal
|
| 31 |
+
name that is the same as the *unqualified-id*. If the lookup in any
|
| 32 |
+
instantiation finds that a *using-declarator* that is not considered to
|
| 33 |
+
name a constructor does do so, or that a *using-declarator* that is
|
| 34 |
+
considered to name a constructor does not, the program is ill-formed.
|
| 35 |
|
| 36 |
If the *using-declarator* names a constructor, it declares that the
|
| 37 |
+
class *inherits* the named set of constructor declarations from the
|
| 38 |
+
nominated base class.
|
| 39 |
+
|
| 40 |
+
[*Note 1*: Otherwise, the *unqualified-id* in the *using-declarator* is
|
| 41 |
+
bound to the *using-declarator*, which is replaced during name lookup
|
| 42 |
+
with the declarations it names [[basic.lookup]]. If such a declaration
|
| 43 |
+
is of an enumeration, the names of its enumerators are not bound. For
|
| 44 |
+
the keyword `typename`, see [[temp.res]]. — *end note*]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
In a *using-declaration* used as a *member-declaration*, each
|
| 47 |
*using-declarator* shall either name an enumerator or have a
|
| 48 |
+
*nested-name-specifier* naming a base class of the current class
|
| 49 |
+
[[expr.prim.this]].
|
| 50 |
|
| 51 |
+
[*Example 1*:
|
| 52 |
|
| 53 |
``` cpp
|
| 54 |
enum class button { up, down };
|
| 55 |
struct S {
|
| 56 |
using button::up;
|
|
|
|
| 59 |
```
|
| 60 |
|
| 61 |
— *end example*]
|
| 62 |
|
| 63 |
If a *using-declarator* names a constructor, its *nested-name-specifier*
|
| 64 |
+
shall name a direct base class of the current class. If the immediate
|
| 65 |
+
(class) scope is associated with a class template, it shall derive from
|
| 66 |
+
the specified base class or have at least one dependent base class.
|
| 67 |
|
| 68 |
+
[*Example 2*:
|
| 69 |
|
| 70 |
``` cpp
|
| 71 |
+
struct B {
|
| 72 |
+
void f(char);
|
| 73 |
+
enum E { e };
|
| 74 |
+
union { int x; };
|
| 75 |
+
};
|
| 76 |
+
|
| 77 |
+
struct C {
|
| 78 |
+
int f();
|
| 79 |
+
};
|
| 80 |
+
|
| 81 |
+
struct D : B {
|
| 82 |
+
using B::f; // OK, B is a base of D
|
| 83 |
+
using B::e; // OK, e is an enumerator of base B
|
| 84 |
+
using B::x; // OK, x is a union member of base B
|
| 85 |
+
using C::f; // error: C isn't a base of D
|
| 86 |
+
void f(int) { f('c'); } // calls B::f(char)
|
| 87 |
+
void g(int) { g('c'); } // recursively calls D::g(int)
|
| 88 |
+
};
|
| 89 |
template <typename... bases>
|
| 90 |
struct X : bases... {
|
| 91 |
+
using bases::f...;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
};
|
| 93 |
+
X<B, C> x; // OK, B::f and C::f named
|
| 94 |
```
|
| 95 |
|
| 96 |
— *end example*]
|
| 97 |
|
| 98 |
[*Note 2*: Since destructors do not have names, a *using-declaration*
|
| 99 |
+
cannot refer to a destructor for a base class. — *end note*]
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
If a constructor or assignment operator brought from a base class into a
|
| 102 |
derived class has the signature of a copy/move constructor or assignment
|
| 103 |
+
operator for the derived class
|
| 104 |
+
[[class.copy.ctor]], [[class.copy.assign]], the *using-declaration* does
|
| 105 |
+
not by itself suppress the implicit declaration of the derived class
|
| 106 |
+
member; the member from the base class is hidden or overridden by the
|
| 107 |
implicitly-declared copy/move constructor or assignment operator of the
|
| 108 |
derived class, as described below.
|
| 109 |
|
| 110 |
A *using-declaration* shall not name a *template-id*.
|
| 111 |
|
| 112 |
+
[*Example 3*:
|
| 113 |
|
| 114 |
``` cpp
|
| 115 |
struct A {
|
| 116 |
template <class T> void f(T);
|
| 117 |
template <class T> struct X { };
|
|
|
|
| 127 |
A *using-declaration* shall not name a namespace.
|
| 128 |
|
| 129 |
A *using-declaration* that names a class member other than an enumerator
|
| 130 |
shall be a *member-declaration*.
|
| 131 |
|
| 132 |
+
[*Example 4*:
|
| 133 |
|
| 134 |
``` cpp
|
| 135 |
struct X {
|
| 136 |
int i;
|
| 137 |
static int s;
|
|
|
|
| 143 |
}
|
| 144 |
```
|
| 145 |
|
| 146 |
— *end example*]
|
| 147 |
|
| 148 |
+
If a declaration is named by two *using-declarator*s that inhabit the
|
| 149 |
+
same class scope, the program is ill-formed.
|
| 150 |
|
| 151 |
+
[*Note 3*: A *using-declarator* whose *nested-name-specifier* names a
|
| 152 |
+
namespace does not name declarations added to the namespace after it.
|
| 153 |
+
Thus, additional overloads added after the *using-declaration* are
|
| 154 |
+
ignored, but default function arguments [[dcl.fct.default]], default
|
| 155 |
+
template arguments [[temp.param]], and template specializations
|
| 156 |
+
[[temp.spec.partial]], [[temp.expl.spec]] are considered. — *end note*]
|
| 157 |
|
| 158 |
+
[*Example 5*:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
``` cpp
|
| 161 |
namespace A {
|
| 162 |
void f(int);
|
| 163 |
}
|
|
|
|
| 177 |
}
|
| 178 |
```
|
| 179 |
|
| 180 |
— *end example*]
|
| 181 |
|
| 182 |
+
If a declaration named by a *using-declaration* that inhabits the target
|
| 183 |
+
scope of another declaration potentially conflicts with it
|
| 184 |
+
[[basic.scope.scope]], and either is reachable from the other, the
|
| 185 |
+
program is ill-formed. If two declarations named by *using-declaration*s
|
| 186 |
+
that inhabit the same scope potentially conflict, either is reachable
|
| 187 |
+
from the other, and they do not both declare functions or function
|
| 188 |
+
templates, the program is ill-formed.
|
| 189 |
|
| 190 |
+
[*Note 4*: Overload resolution possibly cannot distinguish between
|
| 191 |
+
conflicting function declarations. — *end note*]
|
|
|
|
| 192 |
|
| 193 |
+
[*Example 6*:
|
| 194 |
|
| 195 |
``` cpp
|
| 196 |
namespace A {
|
| 197 |
int x;
|
| 198 |
+
int f(int);
|
| 199 |
+
int g;
|
| 200 |
+
void h();
|
| 201 |
}
|
| 202 |
|
| 203 |
namespace B {
|
| 204 |
int i;
|
| 205 |
struct g { };
|
| 206 |
struct x { };
|
| 207 |
void f(int);
|
| 208 |
void f(double);
|
| 209 |
+
void g(char); // OK, hides struct g
|
| 210 |
}
|
| 211 |
|
| 212 |
void func() {
|
| 213 |
int i;
|
| 214 |
+
using B::i; // error: conflicts
|
| 215 |
void f(char);
|
| 216 |
+
using B::f; // OK, each f is a function
|
| 217 |
+
using A::f; // OK, but interferes with B::f(int)
|
| 218 |
+
f(1); // error: ambiguous
|
| 219 |
+
static_cast<int(*)(int)>(f)(1); // OK, calls A::f
|
| 220 |
f(3.5); // calls B::f(double)
|
| 221 |
using B::g;
|
| 222 |
g('a'); // calls B::g(char)
|
| 223 |
struct g g1; // g1 has class type B::g
|
| 224 |
+
using A::g; // error: conflicts with B::g
|
| 225 |
+
void h();
|
| 226 |
+
using A::h; // error: conflicts
|
| 227 |
using B::x;
|
| 228 |
+
using A::x; // OK, hides struct B::x
|
| 229 |
x = 99; // assigns to A::x
|
| 230 |
struct x x1; // x1 has class type B::x
|
| 231 |
}
|
| 232 |
```
|
| 233 |
|
| 234 |
— *end example*]
|
| 235 |
|
| 236 |
+
The set of declarations named by a *using-declarator* that inhabits a
|
| 237 |
+
class `C` does not include member functions and member function
|
| 238 |
+
templates of a base class that correspond to (and thus would conflict
|
| 239 |
+
with) a declaration of a function or function template in `C`.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
|
| 241 |
+
[*Example 7*:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
|
| 243 |
``` cpp
|
| 244 |
struct B {
|
| 245 |
virtual void f(int);
|
| 246 |
virtual void f(char);
|
|
|
|
| 248 |
void h(int);
|
| 249 |
};
|
| 250 |
|
| 251 |
struct D : B {
|
| 252 |
using B::f;
|
| 253 |
+
void f(int); // OK, D::f(int) overrides B::f(int);
|
| 254 |
|
| 255 |
using B::g;
|
| 256 |
void g(char); // OK
|
| 257 |
|
| 258 |
using B::h;
|
| 259 |
+
void h(int); // OK, D::h(int) hides B::h(int)
|
| 260 |
};
|
| 261 |
|
| 262 |
void k(D* p)
|
| 263 |
{
|
| 264 |
p->f(1); // calls D::f(int)
|
|
|
|
| 282 |
D1 d1(0); // error: ambiguous
|
| 283 |
|
| 284 |
struct D2 : B1, B2 {
|
| 285 |
using B1::B1;
|
| 286 |
using B2::B2;
|
| 287 |
+
D2(int); // OK, D2::D2(int) hides B1::B1(int) and B2::B2(int)
|
| 288 |
};
|
| 289 |
D2 d2(0); // calls D2::D2(int)
|
| 290 |
```
|
| 291 |
|
| 292 |
— *end example*]
|
| 293 |
|
| 294 |
+
[*Note 5*: For the purpose of forming a set of candidates during
|
| 295 |
+
overload resolution, the functions named by a *using-declaration* in a
|
| 296 |
+
derived class are treated as though they were direct members of the
|
| 297 |
+
derived class. In particular, the implicit object parameter is treated
|
| 298 |
+
as if it were a reference to the derived class rather than to the base
|
| 299 |
+
class [[over.match.funcs]]. This has no effect on the type of the
|
| 300 |
+
function, and in all other respects the function remains part of the
|
| 301 |
+
base class. — *end note*]
|
| 302 |
|
| 303 |
+
Constructors that are named by a *using-declaration* are treated as
|
| 304 |
though they were constructors of the derived class when looking up the
|
| 305 |
constructors of the derived class [[class.qual]] or forming a set of
|
| 306 |
+
overload candidates
|
| 307 |
+
[[over.match.ctor]], [[over.match.copy]], [[over.match.list]].
|
| 308 |
|
| 309 |
+
[*Note 6*: If such a constructor is selected to perform the
|
| 310 |
initialization of an object of class type, all subobjects other than the
|
| 311 |
base class from which the constructor originated are implicitly
|
| 312 |
initialized [[class.inhctor.init]]. A constructor of a derived class is
|
| 313 |
sometimes preferred to a constructor of a base class if they would
|
| 314 |
otherwise be ambiguous [[over.match.best]]. — *end note*]
|
| 315 |
|
| 316 |
+
In a *using-declarator* that does not name a constructor, every
|
| 317 |
+
declaration named shall be accessible. In a *using-declarator* that
|
| 318 |
+
names a constructor, no access check is performed.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 319 |
|
| 320 |
+
[*Note 7*:
|
| 321 |
|
| 322 |
Because a *using-declarator* designates a base class member (and not a
|
| 323 |
member subobject or a member function of a base class subobject), a
|
| 324 |
*using-declarator* cannot be used to resolve inherited member
|
| 325 |
ambiguities.
|
| 326 |
|
| 327 |
+
[*Example 8*:
|
| 328 |
|
| 329 |
``` cpp
|
| 330 |
struct A { int x(); };
|
| 331 |
struct B : A { };
|
| 332 |
struct C : A {
|
|
|
|
| 345 |
|
| 346 |
— *end example*]
|
| 347 |
|
| 348 |
— *end note*]
|
| 349 |
|
| 350 |
+
A *using-declaration* has the usual accessibility for a
|
| 351 |
+
*member-declaration*. Base-class constructors considered because of a
|
| 352 |
+
*using-declarator* are accessible if they would be accessible when used
|
| 353 |
+
to construct an object of the base class; the accessibility of the
|
| 354 |
+
*using-declaration* is ignored.
|
|
|
|
| 355 |
|
| 356 |
+
[*Example 9*:
|
| 357 |
|
| 358 |
``` cpp
|
| 359 |
class A {
|
| 360 |
private:
|
| 361 |
void f(char);
|
|
|
|
| 372 |
};
|
| 373 |
```
|
| 374 |
|
| 375 |
— *end example*]
|
| 376 |
|
|
|
|
|
|
|
|
|
|
|
|