Access to a class member: section 3.4.5, point 2: point from the N3290 C ++ project

Access to a class member: section 3.4.5, paragraph 2:

If the id expression in the access of a member of the class (5.2.5) is unqualified-id, and the type of the object expression is of the class type C, an unqualified identifier is looked up within the class C. To call a pseudo-destructor (5.2.4), an unqualified identifier is looked up in the context full postfix expression.

here in the statement above: to call the pseudo-destructor (5.2.4), an unqualified identifier is looked up in the context of a full postfix expression.

can anyone explain this in terms of the program (I know about calling a pseudo destructor)?

+4
source share
1 answer

A pseudo-destructor is a destructor-like syntax called in a non-classical type:

typedef int I; I x; xI::~I(); 

If it was parsed β€œnaively,” then the parser will see the following tokens:

unqualified-id ( x ), typename ( I ), :: , bitwise-negate, typename ( I ), ( , ) ,; .

Bitwise negation is a problem because if you just wrote this:

 ~I(); 

Then it would form a valid expression with different semantics. Namely, the same as ~0 . Therefore, the expression above must be analyzed differently in order to take into account the context of the pseudo-destructor.

+3
source

Source: https://habr.com/ru/post/1369471/


All Articles