This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RFC: New C++ Attribute: final
- From: Kevin Atkinson <kevina at gnu dot org>
- To: gcc at gcc dot gnu dot org
- Date: Sat, 28 Feb 2004 21:43:19 -0500 (EST)
- Subject: RFC: New C++ Attribute: final
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.
An example:
class A {
public:
virtual void f();
};
class B {
public:
__attribute__((final)) void f();
};
int main()
{
B * b = new B;
A * a = b;
a->f(); // virtual call
b->f(); // non virtual call since the function in type B is marked
// as final
b->B::f(); // equalvent to the above
}
I have not written any code for GCC yet, but if people think it is a good
idea I may just implement this, as it seams like something that can't be
too difficult to do.
--
http://kevin.atkinson.dhs.org