RFC: New C++ Attribute: final
Joe Buck
Joe.Buck@synopsys.COM
Mon Mar 1 21:22:00 GMT 2004
I'm not going to address all your points, because we will just have to
agree to disagree. However:
On Mon, Mar 01, 2004 at 09:47:33PM +0100, Gabriel Dos Reis wrote:
> For extensibility in C++, you have to work with a reference or a
> pointer to a polymorphic class and the static type is, for the
> majority part, different from the static part. Therefor, the vcall
> would be implied even in presence of "final".
Given virtual Base::func and final Derived::func, if the compiler sees
a reference to Base, it generates a virtual call. If the compiler sees
a reference to Derived, it generates a nonvirtual call, even though
the static type might be something else. So the answer is that sometimes
it is implied and sometimes it is not, but we always call the correct
function.
> (a) and (b) are not the arguments that I would say really argue for
> "final". They just provide opportunities for the opponents to get
> renforced in their opinions.
>
> I find that stating clearly that a non-polymorphic class should not be
> used as a base class (which is known in a more polite way as item xxx
> of Effective C++) is much easier to achieve with final than without.
We pretty much proved that Effective C++'s recommendations are broken. If
you forget how we did that, just supply -Weffc++ to GCC and watch the fun.
In particular, STL gives you seas of warnings, because it cannot be
implemented (with acceptable performance) without deriving from base
classes without using virtual functions or virtual destructors. Our STL
implementation is filled with non-polymorphic classes that are used as
base classes.
More information about the Gcc
mailing list