Does a call to a trivial destructor end the lifetime of an object?
I read this and this but didn't find a good explanation. These threads state that a trivial destructor call has no effect and code like struct A { int x; } a; a.~A(); a.~A();
is legal.
But I found that example in the standard:
struct C { };
void f() {
C * pc = new C;
using C2 = C;
pc->C::~C2(); // OK, destroys *pc
C().C::~C(); // undefined behavior: temporary of type C destroyed twice
using T = int;
0 .T::~T(); // OK, no effect
0.T::~T(); // error: 0.T is a user-defined-floating-point-literal (5.13.8)
}
Here C has trivial destructor but still double destruction of an object of type C has undefined behavior?