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


2788. Correspondence and redeclarations

Section: 6.4.1  [basic.scope.scope]     Status: open     Submitter: Corentin Jabot     Date: 2023-08-09

Consider:

  struct S {
    void f() &;
  };
  void S::f(this S&) {}

Both declarations of S::f correspond (6.4.1 [basic.scope.scope] paragraph 4), but are ill-formed according to 6.6 [basic.link] paragraph 1, because the functions are not of the same type:

For any two declarations of an entity E:

A similar situation arises for the following example:

  struct S {
    void g() &;
  };
  void S::g() { }

Possible resolution:

Add a note in 6.4.1 [basic.scope.scope] paragraph 4 as follows:

[ Note: Two function declarations with different ref-qualifiers or parameter-type-lists do not have the same type even if they correspond (6.6 [basic.link]). -- end note ]
[ Example 2:
  typedef int Int;
  ...
   
    void m();
    void n();
  };

 X::m() & {}       // error: redeclaration of X::m with a different type
 X::n(this X&) {}  // error: redeclaration of X::n with a different type