Hi,
Why not treat as erroneous a new expression that creates an instance of a
class which has a (direct or indirect) base class with a non-virtual
destructor and require implementations issue a diagnostic message? This
would minimize the chances for resource leaks and for undefined behaviour
in
C++ programs.
While it may help protect a programmer from himself, that's not a good
enough reason IMHO. Tools that do static analysis can detect this
kind of problem, perhaps including your compiler when enabling certain
warnings (and I'll admit it may very well be useful if enabled from
time to time.)
That said, there several reasons to not force this rule change,
including:
1) It would break inordinate amounts of existing, completely correct
code.
2) It would be preventing valid use-cases where objects are NOT used
or deleted polymorphically. (The pointer may be stored in pointers
of the dynamic type of the object, so deleting it is fine, or even
if they are converted to base pointers, that doesn't mean they'll
be deleted through those pointers.)