Resolution of B-2 not reflected in B-6 (aka covariant returns)
Martin von Loewis
loewis at informatik.hu-berlin.de
Thu Mar 9 12:41:55 UTC 2000
> I think that is what was meant. To restate:
>
> When a virtual function is declared in a class, it gets a new vtable slot
> unless it overrides a function from the primary base and conversion
> between the two return types does not require an adjustment.
>
> It seems unnecessary to force a new entry if the return types are related
> by single inheritance.
In the B-2 discussion, the notes say
# Agreement was reached to avoid the complication of eliminating some
# of the Vtable entries. Thus, the Vtable will have one entry for each
# accessible return type of a covariant virtual function.
I agree with that resolution; it follows that a new slot is allocated
even if there are no return adjustments. Of course, a smart compiler
would use the same function entry as in the base part, instead of
generating a new one.
Please note that this rule would also apply in case of different cv
qualification, as allowed per 10.3/5
# both pointers or references have the same cvqualification and the
# class type in the return type of D::f has the same cvqualification
# as or less cvqualification than the class type in the return type
# of B::f.
So, in case of
struct Base{
virtual const Base* foo();
};
struct Derived{
virtual Base* foo();
};
there would be two vtable slots for Derived::foo, which would most
likely be implemented by the same entry point.
If that is undesirable, I would not object to re-opening B-2, and
indeed eliminating some vtable entries. However, I think it is fine as
it is now.
Martin
More information about the cxx-abi-dev
mailing list