Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[class.mfct.non-static] p3 class member access transformation in the context where "this" is not permitted #4914

Open
xmh0511 opened this issue Sep 17, 2021 · 1 comment

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Sep 17, 2021

[class.mfct.non-static] p3

When an id-expression ([expr.prim.id]) that is not part of a class member access syntax ([expr.ref]) and not used to form a pointer to member ([expr.unary.op]) is used where the current class is X ([expr.prim.this]), if name lookup ([basic.lookup]) resolves the name in the id-expression to a non-static non-type member of some class C, and if either the id-expression is potentially evaluated or C is X or a base class of X, 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 example

struct B{
    int d;
    void show(decltype(d));  // #1
};

the name d in #1 resolves to the non-static data member of B, the current class is also B, hence the id-expression is transformed into a class member access expression, however, according to [expr.prim.this] p5

The expression this shall not appear in any other context.

The transformation makes an ill-formed.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Sep 18, 2021

Furthermore, consider an example that has more dependency on this pointer

struct C{
    int i;
    void show(decltype((i)));  // #1
};

Note decltype((i)), according to [dcl.type.decltype] p1, the type denoted by it is determined by the value category and type of this->i.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant