This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 116a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2024-12-19
[Accepted as a DR at the June, 2024 meeting.]
(From submission #515.)
Consider:
struct A { static void f() { struct B { void *g() { return this; } }; } };
According to 7.5.3 [expr.prim.this] paragraph 3, this example is ill-formed, because this "appears within" the declaration of a static member function. The qualification "of the current class" can be read as attaching to explicit object member functions only.
Suggested resolution [SUPERSEDED]:
Change in 7.5.3 [expr.prim.this] paragraph 3 as follows:
If a declaration declares a member function or member function template of a class X, the expression this is a prvalue of type “pointer to cv-qualifier-seq X” wherever X is the current class between the optional cv-qualifier-seq and the end of the function-definition, member-declarator , or declarator.It shall not appear within theThe declarationof eitherthat determines the type of this shall declare neither a static member functionornor 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).
CWG 2024-05-03
CWG preferred a smaller surgery to avoid the English parsing issue.
Proposed resolution (approved by CWG 2024-05-17):
Change in 7.5.3 [expr.prim.this] paragraph 3 as follows:
If a declaration declares a member function or member function template of a class X, the expression this is a prvalue of type “pointer to cv-qualifier-seq X” wherever X is the current class between the optional cv-qualifier-seq and the end of the function-definition, member-declarator, or declarator. It shall not appear within the declaration ofeithera staticmember functionoranexplicit 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).