Title
Correspondence and redeclarations
Status
open
Section
6.4.1 [basic.scope.scope]
Submitter
Corentin Jabot

Created on 2023-08-09.00:00:00 last changed 15 months ago

Messages

Date: 2023-08-09.00:00:00

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:
  • If one declares E to be a variable or function, the other shall declare E as one of the same type.
  • ...

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
History
Date User Action Args
2023-08-09 00:00:00admincreate