This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: RFC: New C++ Attribute: final
- From: Joe Buck <Joe dot Buck at synopsys dot COM>
- To: Nathan Sidwell <nathan at codesourcery dot com>
- Cc: Kevin Atkinson <kevina at gnu dot org>,Mark Mielke <mark at mark dot mielke dot cc>, gcc at gcc dot gnu dot org
- Date: Mon, 1 Mar 2004 10:44:53 -0800
- Subject: Re: RFC: New C++ Attribute: final
- References: <Pine.LNX.4.44.0402290149380.30657-100000@kevin-p3.atkinson.dhs.org> <40430E61.7000205@codesourcery.com>
On Mon, Mar 01, 2004 at 10:20:17AM +0000, Nathan Sidwell wrote:
> Kevin Atkinson wrote:
> > Well yes I got the name from Java. But that doesn't mean that it can't be
> > useful is C++ also. Furthermore this attribute is mainly an
> > optimization so your program will still be correct without it.
>
> In Java, the point of 'final' is to say 'not virtual', because all
> non static member functions are implicitly virtual. In C++ there's no need.
This is incorrect. "final" permits a performance win in Java that C++
does not have, as it permits the compiler to eliminate many virtual calls.
The key is that Base::func can be labeled virtual while Derived::func
can be labeled final. You can't do that in C++.
I first saw a proposal for "final" in C++ in the context of a paper on
the implementation of matrix classes of various forms (sparse matrix,
symmetrix matrix, general dense matrix, etc) in 1992. The key observation
is that if we make the base element access method virtual, but then make
the derived element access methods final, we can write algorithms for the
derived classes in a natural way and avoid virtual calls. In the absence
of "final", I've often been reduced to having two forms of calls, a
virtual form and a nonvirtual form, which can be error-prone.