@@ -1172,18 +1172,42 @@ <h4><a href="#vtable-components"> 2.5.2 Virtual Table Components and Order </a><
11721172a virtual function pointer entry is the descriptor.
11731173
11741174< p >
1175- The order of the virtual function pointers in a virtual table is the order
1176- of declaration of the corresponding member functions in the class.
1177- There is an entry for any virtual function declared in a class,
1178- whether it is a new function or overrides a base class function,
1179- unless it overrides a function from the primary base,
1180- and conversion between their return types does not require an adjustment.
1181- (In the case of this exception,
1182- the primary base and the derived class share the virtual table,
1183- and can share the virtual function entry because their 'this' and
1184- result type adjustments are the same.)
1185- If a class has an implicitly-defined virtual destructor,
1186- its entries come after the declared virtual function pointers.
1175+ The order of the virtual function pointers in a virtual table is
1176+ the order of declaration of the corresponding member functions in the class.
1177+ If an implicitly-declared copy assignment operator, move assignment operator,
1178+ or destructor is virtual, it is treated as if it were declared at the end of
1179+ the class, in that order.
1180+ (Implicitly-declared assignment operators may be virtual if
1181+ a base class declares a virtual assignment operator
1182+ taking a reference to a derived class type.)
1183+
1184+ < p >
1185+ An entry is added for every virtual function in a class,
1186+ including deleted functions, unless:
1187+ < ul >
1188+ < li > the function is < tt > consteval</ tt > or
1189+ < li > the function overrides a function from the primary base and
1190+ that override does not require a return-type adjustment.
1191+ </ ul >
1192+
1193+ < p >
1194+ An override requires a return-type adjustment if
1195+ the return types are different and
1196+ have potentially incompatible representations.
1197+ C++ permits an override to differ in return type from the overridden function
1198+ only if both types are pointer-to-class or reference-to-class types and
1199+ the class type < tt > B</ tt > in the overridden function is
1200+ an unambiguous base class of the class type < tt > D</ tt > in the override.
1201+ For the purposes of vtable layout,
1202+ these types are considered to have potentially incompatible representations if:
1203+ < ul >
1204+ < li >
1205+ < tt > B</ tt > is a morally virtual base of < tt > D</ tt >
1206+ (even if < tt > D</ tt > is < tt > final</ tt > and
1207+ the offset of < tt > B</ tt > within < tt > D</ tt > is known to be zero) or
1208+ < li >
1209+ the (static) offset of < tt > B</ tt > within < tt > D</ tt > is non-zero.
1210+ </ ul >
11871211
11881212< p >
11891213When a derived class and its primary base share a virtual table,
@@ -1288,11 +1312,7 @@ <h5> Category 1: Leaf </h5>
12881312
12891313< p >
12901314The virtual table contains offset-to-top and RTTI fields
1291- followed by virtual function pointers.
1292- There is one function pointer entry for each
1293- virtual function declared in the class,
1294- in declaration order,
1295- with any implicitly-defined virtual destructor pair last.
1315+ followed by virtual function pointers (as specified above).
12961316
12971317< p >
12981318< h5 > Category 2: Non-Virtual Bases Only </ h5 >
@@ -1335,22 +1355,8 @@ <h5> Category 2: Non-Virtual Bases Only </h5>
13351355The primary virtual table for the derived class contains entries for
13361356each of the functions in the primary base class virtual table,
13371357replaced by new overriding functions as appropriate. Following these
1338- entries, there is an entry for each virtual function declared in the
1339- derived class (in declaration order) for which one of the following
1340- two conditions holds:
1341- < ul >
1342- < li > The virtual function does not override any function already
1343- appearing in the virtual table.
1344-
1345- < li > The virtual function overrides a function (or functions) appearing
1346- in the virtual table, but the return type of the overrider is
1347- substantively different from the return type of the function(s)
1348- already present. If the return types are different, they are
1349- both pointer-to-class types, or both reference-to-class types.
1350- Let B and D denote the classes, where D is derived from B. The
1351- types are substantively different if B is a morally virtual base of D
1352- or if B is not located at offset zero in D.
1353- </ ul >
1358+ entries, there is an entry for each virtual function pointer for the
1359+ derived class (as specified above).
13541360
13551361< p >
13561362< img src =warning.gif alt ="<b>NOTE</b>: ">
@@ -1455,18 +1461,11 @@ <h5> Category 3: Virtual Bases Only </h5>
14551461and is addressed by the virtual table pointer at the top of the object,
14561462which is not shared
14571463because there are no nearly empty virtual bases to be primary.
1458- It holds the following function pointer entries,
1459- following those of any primary base's virtual table,
1460- in the virtual functions' declaration order:
1461-
1462- < ul >
1463- < p >
1464- < li > Entries for virtual functions introduced by this class,
1465- i.e. those not declared by any of its bases.
1466-
1467- < li > Entries for overridden virtual functions from the base classes,
1468- called replicated entries because they are already
1469- in the secondary virtual tables of the class.
1464+ It holds the virtual function pointer entries for the class.
1465+ This includes all entries overridden from base classes,
1466+ because there is no primary base class;
1467+ such entries are known as replicated entries
1468+ because they are already in the secondary virtual tables of the class.
14701469</ ul >
14711470
14721471< p >
@@ -1508,14 +1507,9 @@ <h5> Category 4: Complex </h5>
15081507
15091508< p >
15101509< li > As for the non-virtual base case,
1511- virtual function pointer entries from the derived class
1512- introductions occur only after the entries from the primary base
1510+ the virtual function pointer entries from the derived class
1511+ (specified above) appear after the entries from the primary base
15131512 class.
1514- There are entries for overridden virtual functions from the primary
1515- base class only if the result types are different (covariant).
1516- For purposes of this case,
1517- the two types are considered different if one of them is a
1518- non-primary or virtual base class of the other.
15191513
15201514</ ul >
15211515
@@ -1754,7 +1748,8 @@ <h4><a href="#vtable-ctor-vtt"> 2.6.2 VTT Order </a></h4>
17541748< p >
17551749Each virtual table address in the VTT is the address to be assigned to the
17561750respective virtual pointer,
1757- i.e. the address of the first virtual function pointer in the virtual table,
1751+ i.e. the address past the end of the typeinfo pointer
1752+ (the address of the first virtual function pointer, if there are any),
17581753not of the first vcall offset.
17591754
17601755< p >
0 commit comments