Title
Overloading virtual functions and functions with trailing requires-clauses
Status
open
Section
6.4.1 [basic.scope.scope]
Submitter
Jiang An

Created on 2020-08-19.00:00:00 last changed 17 months ago

Messages

Date: 2022-11-20.07:54:16

CWG 2022-11-11

This is related to issue 2501. CWG solicits a paper to address this issue.

Date: 2021-11-15.00:00:00

Notes from the November, 2021 teleconference:

The issue has been reopened in response to additional discussion.

Date: 2021-08-15.00:00:00

Rationale (August, 2021):

CWG felt that the current rules are correct; it simply means that only the virtual function can be called, and all other references are simply ambiguous. (See also issue 2501 for a related question dealing with explicit instantiation.

Date: 2022-11-20.07:54:16

According to 6.4.1 [basic.scope.scope] paragraph 3,

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 parameter-type-list,21 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, the same cv-qualifiers (if any) and ref-qualifier (if both have one), or

    • ...

This would indicate that a virtual function (which cannot have a trailing requires-clause, per 11.7.3 [class.virtual] paragraph 6) can be overloaded with a non-virtual member function with the same parameter type list but with a trailing requires-clause. However, this is not implementable on some ABIs, since the mangling of the two functions would be the same. For example:


  #include <type_traits>
  template<class T>
  struct Foo {
     virtual void fun() const {}
     void fun() const requires std::is_object_v<T> {}
  };
  int main() {
    Foo<int>{}.fun();
  }

Should such overloading be ill-formed or conditionally-supported, or should the current rules be kept?

History
Date User Action Args
2022-11-20 07:54:16adminsetmessages: + msg7042
2021-11-15 00:00:00adminsetmessages: + msg6549
2021-11-15 00:00:00adminsetmessages: + msg6548
2020-08-19 00:00:00admincreate