Comeau, g++ (ideone) and EDG accept the following code without diagnostic. Visual C++ compiles successfully, albeit with warning C4624.
class indestructible_base
{
~indestructible_base();
};
class T : indestructible_base
{
public:
//T() {}
};
int main(void) { new T(); }
Uncomment the constructor and it no longer compiles.
Perhaps it's the rule that if an exception occurs inside the constructor, subobjects must be destroyed? Seems odd, since the body is empty and can't cause an exception. Even so, add an exception-specification vouching for the fact that no exception will be thrown (throw()
or noexcept
) and it makes no difference.
Why does a user-declared constructor require access to the base class destructor, while an automatically-generated constructor does not?
This question was inspired by: Preventing a Destructor from Running in C++