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

[dcl.fct.default] Incorrect note on this in default arguments #6558

Open
Eisenwave opened this issue Sep 8, 2023 · 1 comment · May be fixed by #6836
Open

[dcl.fct.default] Incorrect note on this in default arguments #6558

Eisenwave opened this issue Sep 8, 2023 · 1 comment · May be fixed by #6836

Comments

@Eisenwave
Copy link
Contributor

Eisenwave commented Sep 8, 2023

[dcl.fct.default] p8 states:

[Note 5: The keyword this cannot appear in a default argument of a member function; see [expr.prim.this].

class A {
  void f(A* p = this) { }           // error
};

This is incorrect, because the following program is well-formed and the keyword this appears in a default argument:

class A {
  void f(auto = [] {
    struct B { B() { this; } }; // keyword this appeared in a default argument
  }) { }
};

Syntactically, the entire initializer-clause is the default argument, and the this keyword obviously appears inside of it. See [dcl.fct.default] p1

Solution

We could say "cannot directly appear" but this is wishy washy, though correct according to some reader's imaginations.

Wording it in terms of "current class" and whatnot is quite difficult, so maybe we could just say:

Except within the block scope of a lambda-expression, the this keyword cannot ...

It's just a note, so we don't need to make it cover all the cases in all the detail; we just need to make it correct.

@jensmaurer
Copy link
Member

Stuff in the body of a lambda is not a subexpression of the lambda. Maybe we can just say that this cannot appear as a subexpression of a default argument of a member function?

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

Successfully merging a pull request may close this issue.

2 participants