cplusplus / cplusplus/draft

[class.virtual] Overriding virtual function through an explicit object member function CWG2554

Open
#5,144 16 comments 0 reactions 1 assignee View on GitHub

@jensmaurer is already working on this.

Since Dec 10, 2021.

cwg not-editorial
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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.