RFC: New C++ Attribute: final

Gabriel Dos Reis gdr@integrable-solutions.net
Mon Mar 1 21:40:00 GMT 2004


Joe Buck <Joe.Buck@synopsys.COM> writes:

| I'm not going to address all your points, because we will just have to
| agree to disagree.  However:

I have no problem disagreeing with you that your qualification of rigid
does not help the issue.  I, however, would not disgree that "final"
may have some potential benefits for some C++ codes.  That does not
mean I'm for/against that keyword/attribute.  But, I refuse rejecting
opponents' arguments by religious labelling.   

| 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.

There were no doubt the correct function would be called (and I hope
the initial poster at least agree on that).  The issue concerned
rather the "sometines", whether it argues sufficiently strong --
compared to other alternative.

| > (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

No.  What modern C++ proves is that *undiscriminated* applications of
Effective C++'s rules are at odd with current practice.  However,
informed applications (e.g. use of "final" to state that intention in
the class defintion, instead of having the compiler second-guessing)
of those rules are still welcome useful for real-codes.  

| you forget how we did that, just supply -Weffc++ to GCC and watch the fun.

I forgot nothing.  If you google a bit you'll not be surprised to find some
of messages about -Weffec++..

| 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.

Can you assume I know that? If not, just google ;-)  I even happen to
be a perpetrator of that fact elsewhere in our library.

-- Gaby



More information about the Gcc mailing list