RFC: New C++ Attribute: final
Matt Austern
austern@apple.com
Tue Mar 2 20:58:00 GMT 2004
On Feb 28, 2004, at 6:43 PM, Kevin Atkinson wrote:
>
> I have an idea for a new C++ attribute, and would like to know what
> others
> think of it:
>
> 'final'
>
> Marks a virtual function of an entire class as being "final", in the
> sense
> that it can not be overridden in a derived class. If it is applied to
> a
> type then every virtual function in the class will be considered final.
> It will not, however, keep a class from being inherited from.
> Gcc will produce a warning (or maybe an error) if a "final" method is
> overridden.
>
> The primary purpose of this attribute is to serve as an optimization
> hint
> so that a virtual function call does not need to be used. It will also
> allow gcc to perhaps inline the function call if it is appropriate.
My opinion is that this would be better sent to the C++ standards
committee than to the gcc mailing list. That is: I would be much
happier if this were part of portable C++ than if we put it in as an
ad hoc extension.
Rationale: our experiences with language-design-by-compiler
have been mixed. It's unlikely that we'll be able to get all of the
corner cases on a new language feature right if we just say "this
feature should do thus-and-such for this example", because we
have to know what it does for code other than whatever is in a
finite number of examples. And C++ is a complicated enough
language that a new feature is likely to have corner cases and
non-obvious interactions with other features, even if it seems
simple at first.
--Matt
More information about the Gcc
mailing list