This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: RFC: New C++ Attribute: final
Trying to make C++ look like Java, are we? :-)
mark
On Sat, Feb 28, 2004 at 09:43:19PM -0500, 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.
>
> 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
--
mark@mielke.cc/markm@ncf.ca/markm@nortelnetworks.com __________________________
. . _ ._ . . .__ . . ._. .__ . . . .__ | Neighbourhood Coder
|\/| |_| |_| |/ |_ |\/| | |_ | |/ |_ |
| | | | | \ | \ |__ . | | .|. |__ |__ | \ |__ | Ottawa, Ontario, Canada
One ring to rule them all, one ring to find them, one ring to bring them all
and in the darkness bind them...
http://mark.mielke.cc/