C++ Logo

std-discussion

Advanced search

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

From: Yehuda Bernáth <yehudamber_at_[hidden]>
Date: Thu, 27 Aug 2026 20:45:10 +0300
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); }
};

Received on 2026-08-27 17:45:30