Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[expr.prim.this] Clarify that this can appear within a lambda with an explicit object parameter #6855

Open
zygoloid opened this issue Mar 14, 2024 · 0 comments

Comments

@zygoloid
Copy link
Member

[expr.prim.this]/3 says:

[this] shall not appear within the declaration of either a static member function or an explicit object member function of the current class (although its type and value category are defined within such member functions as they are within an implicit object member function).

Multiple implementations have misimplemented this rule for the case of this appearing in a lambda that has an explicit object parameter:

class C {
  void f() {
    [this] (this auto self) { return this->n; };
  }
  int n;
}

Here, I think the three uses of this are not within the declaration of an explicit object member function, because a lambda-expression is not a function declaration at all. And this example should be valid -- there's no problem with using this in a lambda with an explicit object parameter, because the this refers to the object parameter of the enclosing function declaration, not the lambda-expression.

Perhaps it'd be useful to add a note to this parameter to remind the reader that a lambda-expression is not a declaration of a function, so you need to keep looking outwards to find the function you're looking for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant