Created on 2009-03-03.00:00:00 last changed 178 months ago
[Voted into WP at March, 2010 meeting.]
Proposed resolution (October, 2009):
Change _N3225_.7.6.4 [dcl.attr.final] paragraph 1 and add a new paragraph, as follows:
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.
Change the example in _N3225_.7.6.4 [dcl.attr.final] paragraph 3 as follows:
struct B1 { virtual void f [[ final ]] (); }; struct D1 : B1 { void f(); // ill-formed }; struct [[ final ]] B2 { }; struct D2 : B2 { // ill-formed };
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.
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:00 | admin | set | messages: + msg2700 |
2010-03-29 00:00:00 | admin | set | status: ready -> cd2 |
2009-11-08 00:00:00 | admin | set | messages: + msg2358 |
2009-11-08 00:00:00 | admin | set | status: drafting -> ready |
2009-08-03 00:00:00 | admin | set | status: open -> drafting |
2009-03-23 00:00:00 | admin | set | messages: + msg1995 |
2009-03-03 00:00:00 | admin | create |