c++ - Delete objects of incomplete type -
this 1 made me think:
class x; void foo(x* p) { delete p; }
how can possibly delete p
if not know whether x
has visible destructor? g++ 4.5.1 gives 3 warnings:
warning: possible problem detected in invocation of delete operator: warning: 'p' has incomplete type warning: forward declaration of 'struct x'
and says:
note: neither destructor nor class-specific operator delete called, if declared when class defined.
wow... compilers required diagnose situation g++ does? or undefined behavior?
from standard [expr.delete]:
if object being deleted has incomplete class type @ point of deletion , complete class has non-trivial destructor or deallocation function, behavior undefined.
so, it's ub if there's nontrivial stuff do, , it's ok if there isn't. warnings aren't neccessary ub.
Comments
Post a Comment