Skip to content

[basic.scope.scope] Corresponding object members and by-value object parameter #776

@cor3ntin

Description

@cor3ntin

Following discussions about CWG2555

Consider

struct K {
  void f(this K); //#1
  void f(); //#2
};

Here, exactly one (#2) function has an implicit object parameter and no ref qualifier, and after removing references, both have the same type (K) - per https://eel.is/c++draft/over.match.funcs#general-4 - although whether this rule applies could be clearer.

So #1 and #2 correspond, even though they do have different object parameter type (K and K& respectively)
All compilers reject that code.

However, consider a very similar example

struct OK {
  void f(this OK);
  void f() &;
};

Here, no overload has "an implicit object parameter and no ref qualifier" so references are not stripped, we compare K and K&, which are not the same type, the parameter do not correspond and we can declare a distinct overload.

What makes us want a different outcome in both scenarios, when the model is that the lack of & does not implies by value?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions