[class.virtual] Overriding virtual function through an explicit object member function CWG2554
@jensmaurer is already working on this.
Since Dec 10, 2021.
- Dominant language
- TeX
- Stars
- 221
- Forks
- 813
- Avg merge
- 16h 4m
- Merged PRs (30d)
- 36
Description
Consider this example
struct Base{
virtual void show(){} // #1
};
struct Derived: Base{
void show(this Base bptr){} // #2
};
According to [basic.scope.scope] p1, #1 corresponds to #2 as per [basic.scope.scope] p4 if their object parameters should be corresponding. [basic.scope.scope] p3 says that
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 ([dcl.fct]), after removing top-level references, are the same, or
- their object parameters have the same type.
In this case, #1 and #2 satisfy the first bullet since the type of the implicit object parameter of #1 is Base& while the type of the explicit object parameter of #2 is Base, they have the same type after removing the top-level references. Hence, #2 can override#1? Is it the intention after introducing deducing this?
If an explicit object member function can override an implicit object member function, it seems that the class type of the explicit object parameter must be the base class. Is it also the artificial intent?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.