This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: RFC: New C++ Attribute: final
- From: Per Abrahamsen <abraham at dina dot kvl dot dk>
- To: gcc at gcc dot gnu dot org
- Date: Mon, 01 Mar 2004 14:51:18 +0100
- Subject: Re: RFC: New C++ Attribute: final
- Organization: The Church of Emacs
- References: <Pine.LNX.4.44.0402290149380.30657-100000@kevin-p3.atkinson.dhs.org> <40430E61.7000205@codesourcery.com>
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.