Skip to content

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

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?

Activity

  1. cmeerw commented on Oct 12, 2025

    @cmeerw

    I don't think we want different outcomes here, and I'd lean towards making the second case ill-formed as well.

    If we want any of these to be well-formed, I think we also need to discuss how a using-declaration in a derived class then behaves for these cases, i.e.

    struct OK {
      void f(this OK);
      void f() &;
    };
    
    struct D : OK {
      using OK::f;
    };

    as there is special treatment for implicit object member functions, but not for explicit object member functions (over.match.funcs/4)

  2. changed the title [-][basic.scope.scope] Corresponding object members and by-value object parameter[/-] [+]CWG3103 [basic.scope.scope] Corresponding object members and by-value object parameter[/+] on Nov 2, 2025
  3. jensmaurer commented on Nov 2, 2025

    @jensmaurer
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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