This one made me think:
class X;
void foo(X* p)
{
delete p;
}
How can we possibly delete p if we do not even know whether
It is undefined behavior.
However, you can make the compiler check for incomplete types, like boost:
// verify that types are complete for increased safety
template inline void checked_delete(T * x)
{
// intentionally complex - simplification causes regressions
typedef char type_must_be_complete[ sizeof(T)? 1: -1 ];
(void) sizeof(type_must_be_complete);
delete x;
}
Applying sizeof to an incomplete type should trigger an error, and I suppose if that passes with some compiler, then an array of negative size would trigger an error.