CWG Issue 2496 (original) (raw)
This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 118e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2025-11-05
2496._ref-qualifier_s and virtual overriding
Section: 11.7.3 [class.virtual]Status: CD6Submitter: Jens MaurerDate: 2021-06-16
[Accepted as a DR at the October, 2021 meeting.]
According to 11.7.3 [class.virtual] paragraph 2,
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-clause_s, then _G_overrides105 F.
This is different from C++20, where G was considered to hide, rather than to override, F if the _ref-qualifier_s of the declarations are different. This unintentional change could be addressed in one of two ways. To restore the C++20 behavior, the cited paragraph could be amended to:
...a declaration of a member function G corresponds (6.4.1 [basic.scope.scope]) to a declaration of F, ignoring trailing requires-clause_s, and has the same_ref-qualifier (if any), then _G_overrides105 F.
Alternatively, such a situation could be regarded as an ill-formed attempt to override the base class function, which could be specified by adding the following as a new paragraph preceding 11.7.3 [class.virtual] paragraph 7:
The ref-qualifier, or lack thereof, of an overriding function shall be the same as that of the overridden function.
The return type of an overriding function shall be either identical to the return type of the overridden function or_covariant_...
Notes from the August, 2021 teleconference:
CWG preferred the second option.
Proposed resolution, August, 2021:
Add the following as a new paragraph preceding 11.7.3 [class.virtual] paragraph 7:
The ref-qualifier, or lack thereof, of an overriding function shall be the same as that of the overridden function.
The return type of an overriding function shall be either identical to the return type of the overridden function or_covariant_...