This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2024-11-11
Consider:
struct B { virtual void f(); // #1 }; struct D : B { void f(); // #2 };
Subclause 11.7.3 [class.virtual] paragraph 2 says:
If a virtual member function F is declared in a class B, and, in a class D derived (directly or indirectly) from B, a declaration of a member function G corresponds (6.4.1 [basic.scope.scope]) to a declaration of F, ignoring trailing requires-clauses, then G overrides [ Footnote: ... ] F .
Subclause 6.4.1 [basic.scope.scope] paragraph 4 defines "corresponds" as follows:
Two declarations correspond if they (re)introduce the same name, both declare constructors, or both declare destructors, unless
- ...
- each declares a function or function template, except when
- both declare functions with the same non-object-parameter-type-list, equivalent (13.7.7.2 [temp.over.link]) trailing requires-clauses (if any, except as specified in 13.7.5 [temp.friend]), and, if both are non-static members, they have corresponding object parameters, or
- both declare function templates with...
Subclause 6.4.1 [basic.scope.scope] paragraph 3 defines "corresponding object parameters" as follows:
Two non-static member functions have corresponding object parameters if:
- exactly one is an implicit object member function with no ref-qualifier and the types of their object parameters (9.3.4.6 [dcl.fct]), after removing top-level references, are the same, or
- their object parameters have the same type.
In the example, B::f has an object parameter of type B, but D::f has an object parameter of type D. Thus, the two functions do not correspond, and thus D::f does not override B::f. That is an unintended alteration of the status quo ante.
See also issue 2553.
Proposed resolution:
Change in 11.7.3 [class.virtual] paragraph 2 as follows:
If a virtual member function F is declared in a class B, and, in a class D derived (directly or indirectly) from B, a declaration of a member function G corresponds (6.4.1 [basic.scope.scope]) to a declaration of F as if declared in D (12.2.2.1 [over.match.funcs.general]), ignoring trailing requires-clauses, and, if G is an explicit object member function, ignoring object parameters, and, if G is an implicit object member function, F and G have the same ref-qualifier (or absence thereof), then G overrides [ Footnote: ... ] F .
Remove 11.7.3 [class.virtual] paragraph 7 as follows:
The ref-qualifier , or lack thereof, of an overriding function shall be the same as that of the overridden function.