Suppose some type Foo has an overloaded operator-> that returns a Bar*:
struct Foo
{
Bar* operator->();
};
If I want to destruct the returned Bar instance in-place from within the Foo class, can I write the following?
this->~Bar();
g++ does not like that code. It works if I write this:
(*this)->~Bar();
Does the “rescursive forwarding rule” not apply in this case? Why not?
Here is the rule for chaining
->, found in 13.5.6[over.ref]of the standard:Since
thisis a pointer, not a class object, it doesn’t apply.Instead, this rule in 5.2.5 (
[expr.ref]) is applicable: