Consider the following code:
#include <iostream>
typedef int t;
t a=42;
int main()
{
a.t::~t();
std::cout << a; //42
}
I'm expected that a
will be destroyed. But it is not true, why? How does do that pseudo-destructor call will be destroyed the object?
§5.2.4/1:
Where the postfix-expression is the expression of the object for which the call takes place. Thus a pseudo destructor call, as a call to a trivial destructor, does not end the lifetime of the object it is applied to. For instance,
You can't actually call a destructor for scalars, because they don't have one (see [class.dtor]). The statement is solely allowed for template code in which you call the destructor of an object whose type you don't know - it removes the necessity of writing a specialization for scalar types.
It was noted in the comments that [expr.pseudo] does imply the existence of a destructor for scalars by
However, this is inconsistent with other parts of the standard, e.g. §12, which calls a destructor a special member function and mentions that
It appears to be an imprecision created in C++98 days.