Open Eisenwave opened 1 year ago
[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 };
[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:
this
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
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.
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?
[dcl.fct.default] p8 states:
This is incorrect, because the following program is well-formed and the keyword
this
appears 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] p1Solution
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:
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.