Skip to content

CWG2869 [expr.prim.this] Restriction on where this can appear mishandles local classes #515

Closed
cplusplus/draft
#7099
@zygoloid

Description

@zygoloid

Reference (section label): [expr.prim.this]

Issue description: [expr.prim.this]/3 says, in part:

[this] 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).

... which disallows:

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

... because this in g() appears within the declaration of A::f, which is a static member function.

Suggested resolution:

Change in [expr.prim.this]/3:

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

(See also editorial issue cplusplus/draft#6855.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions