RFC: New C++ Attribute: final

Alexandre Oliva aoliva@redhat.com
Tue Mar 2 16:59:00 GMT 2004


On Mar  1, 2004, Gabriel Dos Reis <gdr@integrable-solutions.net> wrote:

> Jeff Sturm <jsturm@one-point.com> writes:
> | >  From a programmer's perspective, why is it desirable to remove the
> | > virtuality?
> | 
> | For C++, I can't think of a good reason besides performance.  In Java, I
> | think 'final' is essential to the security framework.

> There is no doubt that people will construct examples where they
> think they need final for C++.

One of them will probably have to do with passing pointers to member
functions to STL algorithms.  There's no way in C++ that I know to
create a pointer to member that doesn't undergo virtual method
dispatch if the named method turns out to be virtual.  Sure you can
introduce a separate private method and not only call it from the
virtual method, but also use it when you need a non-dynamic pointer to
method, but you have to hope nobody ever decides to introduce a
virtual method in a base class using the same name, to enable a
derived class to preempt your wish for a non-virtual pointer to
method.

Not that I personally find the need for non-virtual pointers to
members in good designs.  It's just that, if final is added to C++,
people will probably want to annotate expressions that take the
address of member functions, and from that even function calls as
final!  The horror! :-) :-)

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Happy GNU Year!                     oliva@{lsd.ic.unicamp.br, gnu.org}
Red Hat GCC Developer                 aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist                Professional serial bug killer



More information about the Gcc mailing list