This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 116a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-12-19


2488. Overloading virtual functions and functions with trailing requires-clauses

Section: 6.4.1  [basic.scope.scope]     Status: open     Submitter: Jiang An     Date: 2020-08-19

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

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?

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.

Notes from the November, 2021 teleconference:

The issue has been reopened in response to additional discussion.

CWG 2022-11-11

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