Title
Meaning of [[final]] applied to a class definition
Status
cd2
Section
_N3225_.7.6.4 [dcl.attr.final]
Submitter
US

Created on 2009-03-03.00:00:00 last changed 178 months ago

Messages

Date: 2010-03-15.00:00:00

[Voted into WP at March, 2010 meeting.]

Date: 2009-10-15.00:00:00

Proposed resolution (October, 2009):

  1. Change _N3225_.7.6.4 [dcl.attr.final] paragraph 1 and add a new paragraph, as follows:

  2. The attribute-token final specifies derivation semantics for a class and overriding semantics for a virtual function. It shall appear at most once in each attribute-list and no attribute-argument-clause shall be present. The attribute applies to class definitions and to virtual member functions being declared in a class definition. If the attribute is specified for a class definition, it is equivalent to being specified for each virtual member function of that class, including inherited member functions.

    If some class B is marked final and a class D is derived from B the program is ill-formed.

  3. Change the example in _N3225_.7.6.4 [dcl.attr.final] paragraph 3 as follows:

  4.   struct B1 {
        virtual void f [[ final ]] ();
      };
    
      struct D1 : B1 {
        void f();          // ill-formed
      };
    
      struct [[ final ]] B2 {
      };
    
      struct D2 : B2 {    // ill-formed
      };
    
Date: 2009-03-15.00:00:00

Notes from the March, 2009 meeting:

The intent of the [[final]] attribute is as an aid in optimization, to avoid virtual function calls when the final overrider is known. It is possible to use the [[final]] attribute to prevent derivation by marking the destructor as [[final]]; in fact, as most polymorphic classes will, as a matter of good programming practice, have a virtual destructor, marking the class as [[final]] will have the effect of preventing derivation.

Nonetheless, the general consensus of the CWG was to change the meaning of class [[final]] to parallel the usage in other languages.

Date: 2011-04-10.00:00:00
N2800 comment USĀ 42

According to _N3225_.7.6.4 [dcl.attr.final] paragraph 1, the [[final]] attribute applied to a class is just a shorthand notation for marking each of the class's virtual functions as [[final]]. This is different from the similar usage in other languages, where it means that the class so marked cannot be used as a base class. This discrepancy is confusing, and the definition used by the other languages is more useful.

History
Date User Action Args
2010-03-29 00:00:00adminsetmessages: + msg2700
2010-03-29 00:00:00adminsetstatus: ready -> cd2
2009-11-08 00:00:00adminsetmessages: + msg2358
2009-11-08 00:00:00adminsetstatus: drafting -> ready
2009-08-03 00:00:00adminsetstatus: open -> drafting
2009-03-23 00:00:00adminsetmessages: + msg1995
2009-03-03 00:00:00admincreate