This is CWG2902

On Thu, Aug 27, 2026, 1:45 PM Yehuda Bernáth via Std-Discussion <std-discussion@lists.isocpp.org> 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@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion


Brian Bi