cplusplus / CWG

Core Working Group
23 stars 7 forks source link

CWG2771 [class.mfct.non.static] p2 The transformation does not apply to the unqualified-id that is an operand of `&` #366

Closed xmh0511 closed 5 months ago

xmh0511 commented 1 year ago

Full name of submitter (unless configured in github; will be published with the issue): Jim X

[class.mfct.non.static] p2 says:

When an id-expression ([expr.prim.id]) that is neither part of a class member access syntax ([expr.ref]) nor the unparenthesized operand of the unary & operator ([expr.unary.op]) is used where the current class is X ([expr.prim.this]), ..., the id-expression is transformed into a class member access expression ([expr.ref]) using (*this) as the postfix-expression to the left of the . operator.

Consider this case:

struct A{
   int a;
   void show(){
      int* r = &a; // #1 
   }
};

According to [class.mfct.non.static] p2, id-expression a(especially, unqualified-id) is the operand of the unary & operand, hence the transformation shouldn't apply to this case, however, all implementations accept this example.

Suggested Resolution

We may want to say

When an id-expression ([expr.prim.id]) that is neither:

part of a class member access syntax ([expr.ref]), nor the unparenthesized operand of the unary & operator ([expr.unary.op]) if the id-expression is an qualified-id

jensmaurer commented 1 year ago

CWG2771