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

Created on 2024-03-14.00:00:00 last changed 1 month ago

Messages

Date: 2024-04-07.16:49:41

Suggested resolution:

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).

Alternative possible resolution:

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-04-07.16:49:41

(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.

History
Date User Action Args
2024-03-17 06:36:43adminsetmessages: + msg7636
2024-03-14 00:00:00admincreate