RFC: New C++ Attribute: final

Per Abrahamsen abraham@dina.kvl.dk
Mon Mar 1 13:51:00 GMT 2004


Nathan Sidwell <nathan@codesourcery.com> writes:

> The point of virtual functions is to allow old code to call new code,
> your 'final' proposal subverts that behaviour.
>
> what is its point?

I'd use it when I want to disallow old code to call new code, in order
to be able to reason about it.  Example:

  class Base
  {
    virtual void bar () = 0;
    void foo ()
    { 
      // Do something...
      bar ();
    }
    // ...
  };
  
  class Derived : public Base
  {
    int x;
    FINAL void bar () 
    {  x = 42; }
    void baz ()
    {
      foo ();
      // This following assertion will always be true, because bar is FINAL.
      assert (x == 42);  
    }
    // ...
  };

It probably enables some automatic optimizations as well (without the
need to rewrite or uglify client code), but I care less about that.

I'd very much like to see something like this in the C++ standard, but
I believe it is against current policy to implement this kind of
experimental language design extensions in GCC.



More information about the Gcc mailing list