How is that possible that it is allowed to delete object with private destructor in the following code? I\'ve reduced real program to the following sample, but it still comp
Because SomeClass
type is not completely declared when invoking operator delete
.
Deleting such a pointer is undefined behavior, but in practice most compilers would just free the memory (if the pointer was non-NULL) and not call the destructor.
For example, g++ will give you a warning about this issue:
foo.cpp: In function 'int main(int, char**)':
foo.cpp:6: warning: possible problem detected in invocation of delete operator:
foo.cpp:5: warning: 'boo' has incomplete type
foo.cpp:1: warning: forward declaration of 'struct SomeClass'
foo.cpp:6: note: neither the destructor nor the class-specific operator delete will be called, even if they are declared when the class is defined.