cplusplus / CWG

Core Working Group
23 stars 7 forks source link

CWG2788 [basic.scope.scope]/p4 Clarifying redeclaration of corresponding functions #394

Open cor3ntin opened 1 year ago

cor3ntin commented 1 year ago

Consider

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

Both declaration of f() correspond ([basic.scope.scope]/p4), but they do not have the same type so this program is ill-formed, per [basic.link]/p11. This is the desired behavior, however it is subtle and could benefit from an example and/or a note in [basic.scope.scope]/p4.

Other example (Thanks Christof!):

struct S {
    void g() &;
};

void S::g() { }

Proposed resolution:

Add a note at the end of [basic.scope.scope]/p4

[Note: Two function declarations that correspond but have different ref-qualifiers or parameter-type-lists do not have the same type [basic.link] —end note].

[Example [2](https://eel.is/c++draft/basic.scope.scope#example-2):
typedef int Int;
enum E : int { a };
void f(int);                    // #1
void f(Int) {}                  // defines #1
void f(E) {}                    // OK, another overload

struct X {
  static void f();
  void f() const;               // error: redeclaration
  void g();
  void g() const;               // OK
  void g() &;                     // error: redeclaration

  void h(this X&, int);
  void h(int) &&;               // OK, another overload
  void j(this const X&);
  void j() const &;             // error: redeclaration
  void k();
  void k(this X&);              // error: redeclaration

+ void m(); 
+ void n();
};

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

— end example]

RealLitb commented 1 year ago

My understanding is that CWG/ is for core issues and draft/ is for editorial issues. You are proposing to change an example. Is this not editorial? I think I'm missing something.

jensmaurer commented 1 year ago

CWG2788