This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFC: New C++ Attribute: final


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]