tmp/tmppgr7b59g/{from.md → to.md}
RENAMED
|
@@ -5,25 +5,24 @@ declared with the keyword `virtual` or if it overrides a virtual member
|
|
| 5 |
function declared in a base class (see below).[^7]
|
| 6 |
|
| 7 |
[*Note 1*: Virtual functions support dynamic binding and
|
| 8 |
object-oriented programming. — *end note*]
|
| 9 |
|
| 10 |
-
A class
|
| 11 |
*polymorphic class*.[^8]
|
| 12 |
|
| 13 |
-
If a virtual member function
|
| 14 |
-
|
| 15 |
-
function
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
convenience we say that any virtual function overrides itself. A
|
| 19 |
-
member function
|
| 20 |
-
unless the most derived class [[intro.object]] of which
|
| 21 |
-
class subobject (if any)
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
ill-formed.
|
| 25 |
|
| 26 |
[*Example 1*:
|
| 27 |
|
| 28 |
``` cpp
|
| 29 |
struct A {
|
|
@@ -49,11 +48,11 @@ void foo() {
|
|
| 49 |
|
| 50 |
``` cpp
|
| 51 |
struct A { virtual void f(); };
|
| 52 |
struct B : A { };
|
| 53 |
struct C : A { void f(); };
|
| 54 |
-
struct D : B, C { }; // OK
|
| 55 |
// for the B and C subobjects, respectively
|
| 56 |
```
|
| 57 |
|
| 58 |
— *end example*]
|
| 59 |
|
|
@@ -123,20 +122,20 @@ A virtual function shall not have a trailing *requires-clause*
|
|
| 123 |
[[dcl.decl]].
|
| 124 |
|
| 125 |
[*Example 5*:
|
| 126 |
|
| 127 |
``` cpp
|
|
|
|
| 128 |
struct A {
|
| 129 |
virtual void f() requires true; // error: virtual function cannot be constrained[temp.constr.decl]
|
| 130 |
};
|
| 131 |
```
|
| 132 |
|
| 133 |
— *end example*]
|
| 134 |
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
[[class.dtor]] and [[class.free]].
|
| 138 |
|
| 139 |
The return type of an overriding function shall be either identical to
|
| 140 |
the return type of the overridden function or *covariant* with the
|
| 141 |
classes of the functions. If a function `D::f` overrides a function
|
| 142 |
`B::f`, the return types of the functions are covariant if they satisfy
|
|
@@ -153,14 +152,15 @@ the following criteria:
|
|
| 153 |
as or less cv-qualification than the class type in the return type of
|
| 154 |
`B::f`.
|
| 155 |
|
| 156 |
If the class type in the covariant return type of `D::f` differs from
|
| 157 |
that of `B::f`, the class type in the return type of `D::f` shall be
|
| 158 |
-
complete at the
|
| 159 |
-
type `D`. When the overriding function
|
| 160 |
-
of the overridden function, its result
|
| 161 |
-
by the (statically chosen) overridden
|
|
|
|
| 162 |
|
| 163 |
[*Example 6*:
|
| 164 |
|
| 165 |
``` cpp
|
| 166 |
class B { };
|
|
@@ -181,11 +181,11 @@ struct No_good : public Base {
|
|
| 181 |
class A;
|
| 182 |
struct Derived : public Base {
|
| 183 |
void vf1(); // virtual and overrides Base::vf1()
|
| 184 |
void vf2(int); // not virtual, hides Base::vf2()
|
| 185 |
char vf3(); // error: invalid difference in return type only
|
| 186 |
-
D* vf4(); // OK
|
| 187 |
A* vf5(); // error: returns pointer to incomplete class
|
| 188 |
void f();
|
| 189 |
};
|
| 190 |
|
| 191 |
void g() {
|
|
@@ -214,12 +214,12 @@ object (the static type) [[expr.call]]. — *end note*]
|
|
| 214 |
|
| 215 |
[*Note 4*: The `virtual` specifier implies membership, so a virtual
|
| 216 |
function cannot be a non-member [[dcl.fct.spec]] function. Nor can a
|
| 217 |
virtual function be a static member, since a virtual function call
|
| 218 |
relies on a specific object for determining which function to invoke. A
|
| 219 |
-
virtual function declared in one class can be declared a friend
|
| 220 |
-
[[class.friend]]
|
| 221 |
|
| 222 |
A virtual function declared in a class shall be defined, or declared
|
| 223 |
pure [[class.abstract]] in that class, or both; no diagnostic is
|
| 224 |
required [[basic.def.odr]].
|
| 225 |
|
|
@@ -328,14 +328,13 @@ void D::f() { ... B::f(); }
|
|
| 328 |
Here, the function call in `D::f` really does call `B::f` and not
|
| 329 |
`D::f`.
|
| 330 |
|
| 331 |
— *end example*]
|
| 332 |
|
| 333 |
-
A
|
| 334 |
-
a function that
|
| 335 |
-
|
| 336 |
-
with a deleted definition.
|
| 337 |
|
| 338 |
A `consteval` virtual function shall not override a virtual function
|
| 339 |
that is not `consteval`. A `consteval` virtual function shall not be
|
| 340 |
overridden by a virtual function that is not `consteval`.
|
| 341 |
|
|
|
|
| 5 |
function declared in a base class (see below).[^7]
|
| 6 |
|
| 7 |
[*Note 1*: Virtual functions support dynamic binding and
|
| 8 |
object-oriented programming. — *end note*]
|
| 9 |
|
| 10 |
+
A class with a virtual member function is called a
|
| 11 |
*polymorphic class*.[^8]
|
| 12 |
|
| 13 |
+
If a virtual member function F is declared in a class B, and, in a class
|
| 14 |
+
D derived (directly or indirectly) from B, a declaration of a member
|
| 15 |
+
function G corresponds [[basic.scope.scope]] to a declaration of F,
|
| 16 |
+
ignoring trailing *requires-clause*s, then G *overrides*[^9]
|
| 17 |
+
|
| 18 |
+
F. For convenience we say that any virtual function overrides itself. A
|
| 19 |
+
virtual member function V of a class object S is a *final overrider*
|
| 20 |
+
unless the most derived class [[intro.object]] of which S is a base
|
| 21 |
+
class subobject (if any) has another member function that overrides V.
|
| 22 |
+
In a derived class, if a virtual member function of a base class
|
| 23 |
+
subobject has more than one final overrider the program is ill-formed.
|
|
|
|
| 24 |
|
| 25 |
[*Example 1*:
|
| 26 |
|
| 27 |
``` cpp
|
| 28 |
struct A {
|
|
|
|
| 48 |
|
| 49 |
``` cpp
|
| 50 |
struct A { virtual void f(); };
|
| 51 |
struct B : A { };
|
| 52 |
struct C : A { void f(); };
|
| 53 |
+
struct D : B, C { }; // OK, A::f and C::f are the final overriders
|
| 54 |
// for the B and C subobjects, respectively
|
| 55 |
```
|
| 56 |
|
| 57 |
— *end example*]
|
| 58 |
|
|
|
|
| 122 |
[[dcl.decl]].
|
| 123 |
|
| 124 |
[*Example 5*:
|
| 125 |
|
| 126 |
``` cpp
|
| 127 |
+
template<typename T>
|
| 128 |
struct A {
|
| 129 |
virtual void f() requires true; // error: virtual function cannot be constrained[temp.constr.decl]
|
| 130 |
};
|
| 131 |
```
|
| 132 |
|
| 133 |
— *end example*]
|
| 134 |
|
| 135 |
+
The *ref-qualifier*, or lack thereof, of an overriding function shall be
|
| 136 |
+
the same as that of the overridden function.
|
|
|
|
| 137 |
|
| 138 |
The return type of an overriding function shall be either identical to
|
| 139 |
the return type of the overridden function or *covariant* with the
|
| 140 |
classes of the functions. If a function `D::f` overrides a function
|
| 141 |
`B::f`, the return types of the functions are covariant if they satisfy
|
|
|
|
| 152 |
as or less cv-qualification than the class type in the return type of
|
| 153 |
`B::f`.
|
| 154 |
|
| 155 |
If the class type in the covariant return type of `D::f` differs from
|
| 156 |
that of `B::f`, the class type in the return type of `D::f` shall be
|
| 157 |
+
complete at the locus [[basic.scope.pdecl]] of the overriding
|
| 158 |
+
declaration or shall be the class type `D`. When the overriding function
|
| 159 |
+
is called as the final overrider of the overridden function, its result
|
| 160 |
+
is converted to the type returned by the (statically chosen) overridden
|
| 161 |
+
function [[expr.call]].
|
| 162 |
|
| 163 |
[*Example 6*:
|
| 164 |
|
| 165 |
``` cpp
|
| 166 |
class B { };
|
|
|
|
| 181 |
class A;
|
| 182 |
struct Derived : public Base {
|
| 183 |
void vf1(); // virtual and overrides Base::vf1()
|
| 184 |
void vf2(int); // not virtual, hides Base::vf2()
|
| 185 |
char vf3(); // error: invalid difference in return type only
|
| 186 |
+
D* vf4(); // OK, returns pointer to derived class
|
| 187 |
A* vf5(); // error: returns pointer to incomplete class
|
| 188 |
void f();
|
| 189 |
};
|
| 190 |
|
| 191 |
void g() {
|
|
|
|
| 214 |
|
| 215 |
[*Note 4*: The `virtual` specifier implies membership, so a virtual
|
| 216 |
function cannot be a non-member [[dcl.fct.spec]] function. Nor can a
|
| 217 |
virtual function be a static member, since a virtual function call
|
| 218 |
relies on a specific object for determining which function to invoke. A
|
| 219 |
+
virtual function declared in one class can be declared a friend
|
| 220 |
+
[[class.friend]] in another class. — *end note*]
|
| 221 |
|
| 222 |
A virtual function declared in a class shall be defined, or declared
|
| 223 |
pure [[class.abstract]] in that class, or both; no diagnostic is
|
| 224 |
required [[basic.def.odr]].
|
| 225 |
|
|
|
|
| 328 |
Here, the function call in `D::f` really does call `B::f` and not
|
| 329 |
`D::f`.
|
| 330 |
|
| 331 |
— *end example*]
|
| 332 |
|
| 333 |
+
A deleted function [[dcl.fct.def]] shall not override a function that is
|
| 334 |
+
not deleted. Likewise, a function that is not deleted shall not override
|
| 335 |
+
a deleted function.
|
|
|
|
| 336 |
|
| 337 |
A `consteval` virtual function shall not override a virtual function
|
| 338 |
that is not `consteval`. A `consteval` virtual function shall not be
|
| 339 |
overridden by a virtual function that is not `consteval`.
|
| 340 |
|