Why would deleting an object through void*
be undefined behavior, rather than compilation error?
void foo(void* p) {
delete p;
}
This code compiles and produces code, albeit with the warning on gcc and clang (surprisingly, ICC doesn't give a warning):
:2:5: warning: cannot delete expression with pointer-to-'void' type 'void *' [-Wdelete-incomplete]
Why is not simply malformed program with invalid syntax? Looks like Standard doesn't spend too much time on it, saying in [expr.delete]
that
This implies that an object cannot be deleted using a pointer of type void* because void is not an object type.
Would there be any reason I am missing why this does not trigger a hard compilation error?