C++ Logo

std-discussion

Advanced search

Re: [expr.prim.id.general] Class member access transformation where `this` is not available

From: Brian Bi <bbi5291_at_[hidden]>
Date: Thu, 27 Aug 2026 15:47:21 -0400
This is CWG2902

On Thu, Aug 27, 2026, 1:45 PM Yehuda BernĂ¡th via Std-Discussion <
std-discussion_at_[hidden]> wrote:

> According to [expr.prim.id.general]/2, if an id-expression denotes a
> non-static member of the *current class* or one of its bases, it is
> transformed into a class member access expression using *this as the
> object, even if it is not potentially evaluated (e.g. it appears inside a
> decltype or sizeof).
> The term "the current class" is defined in [expr.prim.this]/2 as follows:
>
>> The *current class* at a program point is the class associated with the
>> innermost class scope containing that point.
>>
> So there is a current class in many places where this cannot be used,
> like static member functions and member types. Does it mean usage of a
> non-static member of the class in such a context, even inside an
> unevaluated expression, should be transformed into a member access on
> *this and therefore be ill-formed? It seems like all compilers accept
> this code:
> struct S
> {
> int m;
> static auto f() { return sizeof(m); }
> };
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>


*Brian Bi*

Received on 2026-08-27 19:47:37