Title
this in local classes
Status
tentatively ready
Section
7.5.2 [expr.prim.this]
Submitter
Richard Smith

Created on 2024-03-14.00:00:00 last changed 4 weeks ago

Messages

Date: 2024-05-17.22:24:28

Proposed resolution (approved by CWG 2024-05-17):

Change in 7.5.2 [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 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).
Date: 2024-05-17.22:24:28

CWG 2024-05-03

CWG preferred a smaller surgery to avoid the English parsing issue.

Date: 2024-05-13.09:44:12

Suggested resolution [SUPERSEDED]:

Change in 7.5.2 [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 The declaration of either that determines the type of this shall declare neither a static member function or nor 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).
Date: 2024-05-13.09:44:12

(From submission #515.)

Consider:

  struct A {
    static void f() {
      struct B {
        void *g() { return this; }
       };
     }
  };

According to 7.5.2 [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.

History
Date User Action Args
2024-05-17 22:24:28adminsetmessages: + msg7700
2024-05-17 22:24:28adminsetstatus: review -> tentatively ready
2024-05-13 09:44:12adminsetmessages: + msg7696
2024-05-13 09:44:12adminsetstatus: open -> review
2024-03-17 06:36:43adminsetmessages: + msg7636
2024-03-14 00:00:00admincreate